using MktXService.Domain.SeedWork;

namespace MktXService.Domain.AggregatesModel.CampaignAggregate;

/// <summary>
/// EN: Campaign status enumeration following type-safe enum pattern.
/// VI: Enumeration trạng thái chiến dịch theo pattern enum an toàn kiểu.
/// </summary>
public class CampaignStatus : Enumeration
{
    /// <summary>
    /// EN: Draft status - being prepared
    /// VI: Trạng thái nháp - đang chuẩn bị
    /// </summary>
    public static CampaignStatus Draft = new(1, nameof(Draft));

    /// <summary>
    /// EN: Scheduled status - waiting to start
    /// VI: Trạng thái đã lên lịch - đang chờ bắt đầu
    /// </summary>
    public static CampaignStatus Scheduled = new(2, nameof(Scheduled));

    /// <summary>
    /// EN: Running status - actively sending messages
    /// VI: Trạng thái đang chạy - đang gửi tin nhắn
    /// </summary>
    public static CampaignStatus Running = new(3, nameof(Running));

    /// <summary>
    /// EN: Paused status - temporarily stopped
    /// VI: Trạng thái tạm dừng - tạm thời dừng
    /// </summary>
    public static CampaignStatus Paused = new(4, nameof(Paused));

    /// <summary>
    /// EN: Completed status - finished execution
    /// VI: Trạng thái hoàn thành - đã kết thúc
    /// </summary>
    public static CampaignStatus Completed = new(5, nameof(Completed));

    /// <summary>
    /// EN: Cancelled status - cancelled by user
    /// VI: Trạng thái đã hủy - bị hủy bởi người dùng
    /// </summary>
    public static CampaignStatus Cancelled = new(6, nameof(Cancelled));

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

    public static IEnumerable<CampaignStatus> List() => GetAll<CampaignStatus>();

    public static CampaignStatus FromName(string name)
    {
        var status = List().SingleOrDefault(s => 
            string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));

        if (status is null)
            throw new ArgumentException($"Possible values for CampaignStatus: {string.Join(",", List().Select(s => s.Name))}");

        return status;
    }

    public static CampaignStatus From(int id)
    {
        var status = List().SingleOrDefault(s => s.Id == id);

        if (status is null)
            throw new ArgumentException($"Possible values for CampaignStatus: {string.Join(",", List().Select(s => s.Name))}");

        return status;
    }
}
