namespace JobTrackerApi.Models;

public static class OperationStatuses
{
    public const string Queued = "queued";
    public const string Running = "running";
    public const string WaitingForRetry = "waiting_for_retry";
    public const string WaitingForExternalFallback = "waiting_for_external_fallback";
    public const string Succeeded = "succeeded";
    public const string Failed = "failed";
    public const string Cancelled = "cancelled";

    public static bool IsTerminal(string status) => status is Succeeded or Failed or Cancelled;
}

public sealed class UserOperation
{
    public Guid Id { get; set; }
    public string OwnerUserId { get; set; } = string.Empty;
    public string TaskType { get; set; } = string.Empty;
    public string IdempotencyKey { get; set; } = string.Empty;
    public string Status { get; set; } = OperationStatuses.Queued;
    public int Priority { get; set; }
    public string EntitlementDecision { get; set; } = string.Empty;
    public string PrivacyPolicy { get; set; } = string.Empty;
    public string? SubjectType { get; set; }
    public string? SubjectId { get; set; }
    public string? Provider { get; set; }
    public string? Model { get; set; }
    public int AttemptCount { get; set; }
    public int MaxAttempts { get; set; } = 3;
    public DateTime CreatedAtUtc { get; set; }
    public DateTime AvailableAtUtc { get; set; }
    public DateTime? StartedAtUtc { get; set; }
    public DateTime? CompletedAtUtc { get; set; }
    public DateTime? DeadlineAtUtc { get; set; }
    public DateTime? CancellationRequestedAtUtc { get; set; }
    public string? LeaseToken { get; set; }
    public DateTime? LeaseExpiresAtUtc { get; set; }
    public DateTime? LastHeartbeatAtUtc { get; set; }
    public string? ProgressStage { get; set; }
    public int? ProgressPercent { get; set; }
    public string? FailureCategory { get; set; }
    public string? FailureMessage { get; set; }
    public string? ResultReference { get; set; }
}
