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

namespace Insight.Infrastructure.Entities;

public static partial class MongoDatabaseExtensions
{
    public static IMongoCollection<TaskEntity> Task(this IMongoDatabase database) => database.GetCollection<TaskEntity>("task");
}

[BsonIgnoreExtraElements]
public class TaskEntity
{
    [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; }

    [BsonIgnore]
    public Func<CancellationToken, Task>? Action { get; set; }
}