using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System.Text.Json.Serialization;
using Vaitr.Scheduler;

namespace Insight.Infrastructure.Entities;

public static partial class MongoDatabaseExtensions
{
    public static IMongoCollection<JobEntity> Job(this IMongoDatabase database) => database.GetCollection<JobEntity>("job");
}

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

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

    [BsonElement("update")]
    public DateTime? Update { get; set; }

    [BsonElement("name")]
    public string? Name { get; set; }

    [BsonElement("description")]
    public string? Description { get; set; }

    [BsonElement("state"), BsonRepresentation(BsonType.String)]
    public TaskState State { get; set; }

    [BsonElement("timeout")]
    public TimeSpan Timeout { get; set; }

    [BsonElement("executed")]
    public DateTime Executed { get; set; }

    [BsonElement("disabled")]
    public bool Disabled { get; set; }
}