using Jiaowu.Api.Domain.Common;

namespace Jiaowu.Api.Domain.System;

public sealed class BackgroundJobOutboxMessage : EntityBase
{
    public BackgroundJobKind JobKind { get; set; }
    public Guid JobId { get; set; }
    public BackgroundJobOutboxState State { get; set; } =
        BackgroundJobOutboxState.Pending;
    public int PublishAttempts { get; set; }
    public int ProcessingAttempts { get; set; }
    public DateTime? PublishedAt { get; set; }
    public Guid? ProcessingToken { get; set; }
    public DateTime? LeaseExpiresAt { get; set; }
    public DateTime? CompletedAt { get; set; }
    public string? LastError { get; set; }

    public static BackgroundJobOutboxMessage Create(
        BackgroundJobKind jobKind,
        Guid jobId) =>
        new()
        {
            JobKind = jobKind,
            JobId = jobId
        };
}

public enum BackgroundJobKind
{
    AutomaticSchedule = 1,
    SchedulePublish = 2,
    MakeupExamAuto = 3,
    ExamArrangement = 4,
    ExamSignInExport = 5,
    ExamPublish = 6,
    CourseGradeStatisticsRefresh = 7
}

public enum BackgroundJobOutboxState
{
    Pending = 1,
    Publishing = 2,
    Published = 3,
    Processing = 4,
    Completed = 5
}
