using AdsManagerService.Domain.SeedWork;

namespace AdsManagerService.Domain.AggregatesModel.CampaignAggregate;

/// <summary>
/// EN: Campaign status enumeration using smart enum pattern.
/// VI: Enum trạng thái chiến dịch sử dụng smart enum pattern.
/// </summary>
public class CampaignStatus : Enumeration
{
    public static readonly CampaignStatus Draft = new(1, nameof(Draft).ToLowerInvariant());
    public static readonly CampaignStatus Active = new(2, nameof(Active).ToLowerInvariant());
    public static readonly CampaignStatus Paused = new(3, nameof(Paused).ToLowerInvariant());
    public static readonly CampaignStatus Completed = new(4, nameof(Completed).ToLowerInvariant());
    public static readonly CampaignStatus Archived = new(5, nameof(Archived).ToLowerInvariant());

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

    /// <summary>
    /// EN: Get all possible campaign statuses.
    /// VI: Lấy tất cả trạng thái chiến dịch có thể.
    /// </summary>
    public static IEnumerable<CampaignStatus> List() =>
        new[] { Draft, Active, Paused, Completed, Archived };

    /// <summary>
    /// EN: Get status by name.
    /// VI: Lấy trạng thái theo tên.
    /// </summary>
    public static CampaignStatus FromName(string name) =>
        List().FirstOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase))
        ?? throw new ArgumentException($"Invalid campaign status: {name}");

    /// <summary>
    /// EN: Get status by id.
    /// VI: Lấy trạng thái theo id.
    /// </summary>
    public static CampaignStatus From(int id) =>
        List().FirstOrDefault(s => s.Id == id)
        ?? throw new ArgumentException($"Invalid campaign status id: {id}");
}
