using FluentValidation;
using SIGCM2.Application.Common;
using SIGCM2.Domain.Pricing.ChargeableChars;
using SIGCM2.Domain.Pricing.WordCounter;

namespace SIGCM2.Application.Pricing.ChargeableChars.Create;

/// <summary>
/// PRC-001 — FluentValidation validator for CreateChargeableCharConfigCommand.
/// Injects TimeProvider for today_AR (Cat2, never DateTime.Now).
/// </summary>
public sealed class CreateChargeableCharConfigCommandValidator
    : AbstractValidator<CreateChargeableCharConfigCommand>
{
    public CreateChargeableCharConfigCommandValidator(TimeProvider timeProvider)
    {
        var today = timeProvider.GetArgentinaToday();

        RuleFor(x => x.Symbol)
            .NotEmpty()
            .WithMessage("Symbol no puede estar vacío.")
            .MaximumLength(4)
            .WithMessage("Symbol no puede exceder 4 caracteres.")
            .Must(s => !WordCounterService.ContainsEmoji(s))
            .WithMessage("Symbol no puede contener emojis. Usá símbolos ASCII o latinos (ej: $, %, !, ¡).");

        RuleFor(x => x.Category)
            .NotEmpty()
            .WithMessage("Category no puede estar vacío.")
            .Must(ChargeableCharCategories.IsValid)
            .WithMessage($"Category inválida. Valores válidos: {string.Join(", ", new[] { ChargeableCharCategories.Currency, ChargeableCharCategories.Percentage, ChargeableCharCategories.Exclamation, ChargeableCharCategories.Question, ChargeableCharCategories.Other })}.");

        RuleFor(x => x.PricePerUnit)
            .GreaterThanOrEqualTo(0m)
            .WithMessage("PricePerUnit debe ser >= 0. Usá 0 para desactivar el cobro de este símbolo (opt-in billing).");

        RuleFor(x => x.ValidFrom)
            .GreaterThanOrEqualTo(today)
            .WithMessage($"ValidFrom debe ser >= hoy ({today:yyyy-MM-dd} ART). No se permiten configuraciones con fecha retroactiva.");
    }
}
