using FluentValidation;

namespace Baya.Application.Features.Bnpl.Commands.RevertBnplOrder;

public sealed class RevertBnplOrderCommandValidator : AbstractValidator<RevertBnplOrderCommand>
{
    public RevertBnplOrderCommandValidator()
    {
        RuleFor(x => x.BnplTransactionId).GreaterThan(0);

        // A partial revert must be strictly lower than the full order (RefundPercentage < 1); 1 = full revert.
        When(x => x.RefundPercentage.HasValue, () =>
        {
            RuleFor(x => x.RefundPercentage!.Value)
                .GreaterThan(0m).LessThanOrEqualTo(1m)
                .WithMessage("refund_percentage must be a fraction in (0, 1].");
        });

        RuleFor(x => x.ReasonNotes).MaximumLength(1000);
    }
}
