using MktXService.Domain.SeedWork;

namespace MktXService.Domain.AggregatesModel.ContactAggregate;

/// <summary>
/// EN: Tag entity for contact classification.
/// VI: Entity tag để phân loại liên hệ.
/// </summary>
public class ContactTag : Entity
{
    private string _name = null!;
    private DateTime _createdAt;

    /// <summary>
    /// EN: Tag name.
    /// VI: Tên tag.
    /// </summary>
    public string Name => _name;

    /// <summary>
    /// EN: Parent contact ID.
    /// VI: ID liên hệ cha.
    /// </summary>
    public Guid ContactId { get; private set; }

    /// <summary>
    /// EN: Creation timestamp.
    /// VI: Thời gian tạo.
    /// </summary>
    public DateTime CreatedAt => _createdAt;

    /// <summary>
    /// EN: Private constructor for EF Core.
    /// VI: Constructor private cho EF Core.
    /// </summary>
    protected ContactTag()
    {
    }

    /// <summary>
    /// EN: Create a new contact tag.
    /// VI: Tạo một tag liên hệ mới.
    /// </summary>
    public ContactTag(Guid contactId, string name) : this()
    {
        if (string.IsNullOrWhiteSpace(name))
            throw new ArgumentException("Tag name cannot be empty", nameof(name));

        Id = Guid.NewGuid();
        ContactId = contactId;
        _name = name.ToLowerInvariant().Trim();
        _createdAt = DateTime.UtcNow;
    }
}
