using FluentValidation;

namespace Baya.Application.Features.PartnerCenters.Commands.UpdatePartnerCenter;

public sealed class UpdatePartnerCenterCommandValidator : AbstractValidator<UpdatePartnerCenterCommand>
{
    public UpdatePartnerCenterCommandValidator()
    {
        // Id is route-supplied (merged via `with`), so it is not validated here.
        RuleFor(x => x.Name).NotEmpty().MaximumLength(300);
        RuleFor(x => x.LegalEntityType).MaximumLength(30);
        RuleFor(x => x.MohEstablishmentPermitNo).NotEmpty().MaximumLength(100);
        RuleFor(x => x.TechnicalDirectorLicenseNo).MaximumLength(100);
        RuleFor(x => x.EnamadCode).MaximumLength(100);
        RuleFor(x => x.AdminUserId).GreaterThan(0);

        RuleFor(x => x.CommissionRate)
            .InclusiveBetween(0m, 0.9999m)
            .When(x => x.CommissionRate.HasValue);

        RuleFor(x => x.SettlementIban)
            .NotEmpty()
            .MaximumLength(34)
            .When(x => x.IsMerchantOfRecord)
            .WithMessage("A merchant-of-record center requires a settlement IBAN.");

        RuleFor(x => x.SettlementIban).MaximumLength(34).When(x => !x.IsMerchantOfRecord);
    }
}
