namespace ChatService.Domain.AggregatesModel.UserAggregate;

using ChatService.Domain.SeedWork;

/// <summary>
/// EN: User online status enumeration.
/// VI: Enumeration trạng thái online của user.
/// </summary>
public class UserStatus : Enumeration
{
    public static readonly UserStatus Offline = new(1, nameof(Offline).ToLowerInvariant());
    public static readonly UserStatus Online = new(2, nameof(Online).ToLowerInvariant());
    public static readonly UserStatus Away = new(3, nameof(Away).ToLowerInvariant());
    public static readonly UserStatus DoNotDisturb = new(4, nameof(DoNotDisturb).ToLowerInvariant());

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

    public static IEnumerable<UserStatus> List() =>
        new[] { Offline, Online, Away, DoNotDisturb };

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

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

        return state;
    }

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

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

        return state;
    }
}
