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<TriggerEntity> Trigger(this IMongoDatabase database) => database.GetCollection<TriggerEntity>("trigger");
}

public class TriggerEntity
{
    [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("mode")]
    public ScheduleMode Mode { get; set; }

    [BsonElement("date_start")]
    public DateTime StartTime { get; set; }

    [BsonElement("date_end")]
    public DateTime? EndTime { get; set; }

    [BsonElement("interval")]
    public TimeSpan? Interval { get; set; }

    public enum ScheduleMode
    {
        Single, Loop
    }
}