namespace ChatService.Domain.AggregatesModel.ConversationAggregate;

using ChatService.Domain.SeedWork;

/// <summary>
/// EN: Conversation type enumeration.
/// VI: Enumeration loại cuộc hội thoại.
/// </summary>
public class ConversationType : Enumeration
{
    /// <summary>
    /// EN: Direct 1:1 conversation between two users.
    /// VI: Hội thoại trực tiếp 1:1 giữa hai users.
    /// </summary>
    public static readonly ConversationType Direct = new(1, nameof(Direct).ToLowerInvariant());

    /// <summary>
    /// EN: Group conversation with multiple users.
    /// VI: Hội thoại nhóm với nhiều users.
    /// </summary>
    public static readonly ConversationType Group = new(2, nameof(Group).ToLowerInvariant());

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

    public static IEnumerable<ConversationType> List() =>
        new[] { Direct, Group };

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

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

        return state;
    }

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

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

        return state;
    }
}
