using IamService.Domain.SeedWork;

namespace IamService.Domain.AggregatesModel.AccessRequestAggregate;

/// <summary>
/// EN: Access request status enumeration.
/// VI: Enumeration trạng thái yêu cầu truy cập.
/// </summary>
public class AccessRequestStatus : Enumeration
{
    /// <summary>
    /// EN: Request is being drafted, not yet submitted.
    /// VI: Request đang được soạn, chưa gửi.
    /// </summary>
    public static readonly AccessRequestStatus Draft = new(1, nameof(Draft));

    /// <summary>
    /// EN: Request submitted and waiting for approval.
    /// VI: Request đã gửi và đang chờ phê duyệt.
    /// </summary>
    public static readonly AccessRequestStatus Pending = new(2, nameof(Pending));

    /// <summary>
    /// EN: Request approved by all approvers.
    /// VI: Request được phê duyệt bởi tất cả approver.
    /// </summary>
    public static readonly AccessRequestStatus Approved = new(3, nameof(Approved));

    /// <summary>
    /// EN: Request rejected by an approver.
    /// VI: Request bị từ chối bởi approver.
    /// </summary>
    public static readonly AccessRequestStatus Rejected = new(4, nameof(Rejected));

    /// <summary>
    /// EN: Request cancelled by requester.
    /// VI: Request bị hủy bởi người yêu cầu.
    /// </summary>
    public static readonly AccessRequestStatus Cancelled = new(5, nameof(Cancelled));

    /// <summary>
    /// EN: Request expired due to timeout.
    /// VI: Request hết hạn do quá thời gian.
    /// </summary>
    public static readonly AccessRequestStatus Expired = new(6, nameof(Expired));

    public AccessRequestStatus(int id, string name) : base(id, name)
    {
    }

    public static IEnumerable<AccessRequestStatus> GetAll() =>
    [
        Draft,
        Pending,
        Approved,
        Rejected,
        Cancelled,
        Expired
    ];

    public static AccessRequestStatus? FromId(int id) => id switch
    {
        1 => Draft,
        2 => Pending,
        3 => Approved,
        4 => Rejected,
        5 => Cancelled,
        6 => Expired,
        _ => null
    };

    public bool IsTerminal => this == Approved || this == Rejected || this == Cancelled || this == Expired;
}
