using ColaFlow.Shared.Kernel.Common;

namespace ColaFlow.Modules.Identity.Domain.Aggregates.Tenants;

public sealed class TenantName : ValueObject
{
    public string Value { get; }

    private TenantName(string value)
    {
        Value = value;
    }

    public static TenantName Create(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new ArgumentException("Tenant name cannot be empty", nameof(value));

        if (value.Length < 2)
            throw new ArgumentException("Tenant name must be at least 2 characters", nameof(value));

        if (value.Length > 100)
            throw new ArgumentException("Tenant name cannot exceed 100 characters", nameof(value));

        return new TenantName(value.Trim());
    }

    protected override IEnumerable<object> GetAtomicValues()
    {
        yield return Value;
    }

    public override string ToString() => Value;

    // Implicit conversion
    public static implicit operator string(TenantName name) => name.Value;
}
