using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace StellaOps.Scanner.Storage.Catalog;

public enum JobState
{
    Pending,
    Running,
    Succeeded,
    Failed,
    Cancelled,
}

[BsonIgnoreExtraElements]
public sealed class JobDocument
{
    [BsonId]
    public string Id { get; set; } = string.Empty;

    [BsonElement("kind")]
    public string Kind { get; set; } = string.Empty;

    [BsonElement("state")]
    public JobState State { get; set; } = JobState.Pending;

    [BsonElement("args")]
    public BsonDocument Arguments { get; set; }
        = new();

    [BsonElement("createdAt")]
    public DateTime CreatedAtUtc { get; set; }
        = DateTime.UtcNow;

    [BsonElement("startedAt")]
    [BsonIgnoreIfNull]
    public DateTime? StartedAtUtc { get; set; }
        = null;

    [BsonElement("completedAt")]
    [BsonIgnoreIfNull]
    public DateTime? CompletedAtUtc { get; set; }
        = null;

    [BsonElement("heartbeatAt")]
    [BsonIgnoreIfNull]
    public DateTime? HeartbeatAtUtc { get; set; }
        = null;

    [BsonElement("error")]
    [BsonIgnoreIfNull]
    public string? Error { get; set; }
        = null;
}
