using ColaFlow.Domain.Common;
using ColaFlow.Domain.Exceptions;

namespace ColaFlow.Domain.ValueObjects;

/// <summary>
/// ProjectKey Value Object (e.g., "COLA", "FLOW")
/// </summary>
public sealed class ProjectKey : ValueObject
{
    public string Value { get; private set; }

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

    public static ProjectKey Create(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
            throw new DomainException("Project key cannot be empty");

        if (value.Length > 10)
            throw new DomainException("Project key cannot exceed 10 characters");

        if (!System.Text.RegularExpressions.Regex.IsMatch(value, "^[A-Z0-9]+$"))
            throw new DomainException("Project key must contain only uppercase letters and numbers");

        return new ProjectKey(value);
    }

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

    public override string ToString() => Value;
}
