using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System.Text.Json.Serialization;
using Vaitr.Scheduler;
using static Insight.Infrastructure.Entities.TriggerEntity;

namespace Insight.Infrastructure.Entities;

public static partial class MongoDatabaseExtensions
{
    public static IMongoCollection<AgentLogEntity> JobLog(this IMongoDatabase database) => database.GetCollection<AgentLogEntity>("job_log");
}

[BsonIgnoreExtraElements]
public class JobLogEntity
{
    [BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
    public string? Id { get; set; }

    [BsonElement("_job"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("job")]
    public string? Job { get; set; }

    [BsonElement("insert")]
    public DateTime? Insert { get; set; }

    [BsonElement("timestamp")]
    public DateTime? Timestamp { get; set; }

    [BsonElement("status"), BsonRepresentation(BsonType.String)]
    public TaskState? Status { get; set; }

    [BsonElement("mode"), BsonRepresentation(BsonType.String)]
    public ScheduleMode? Mode { get; set; }

    [BsonElement("message")]
    public string? Message { get; set; }
}