using Baya.Domain.Entities.Bnpl;
using FluentValidation;

namespace Baya.Application.Features.Bnpl.Queries.CheckBnplEligibility;

public sealed class CheckBnplEligibilityQueryValidator : AbstractValidator<CheckBnplEligibilityQuery>
{
    public CheckBnplEligibilityQueryValidator()
    {
        RuleFor(x => x.BookingRequestId).GreaterThan(0);
        RuleFor(x => x.ProviderCode)
            .NotEmpty()
            .Must(BnplProviderCodes.IsKnown)
            .WithMessage("provider_code must be one of snapppay, digipay, tara, torobpay, balinyaar.");
        // The D3 credit inquiry is consented: when national id / mobile are supplied, consent must be granted.
        RuleFor(x => x.Consent)
            .Equal(true)
            .When(x => !string.IsNullOrWhiteSpace(x.NationalId) || !string.IsNullOrWhiteSpace(x.Mobile))
            .WithMessage("Consent is required to run the credit inquiry.");
    }
}
