using Baya.Domain.Entities.Booking;
using FluentValidation;

namespace Baya.Application.Features.Bookings.Commands.UpsertCancellationPolicy;

public sealed class UpsertCancellationPolicyCommandValidator : AbstractValidator<UpsertCancellationPolicyCommand>
{
    public UpsertCancellationPolicyCommandValidator()
    {
        RuleFor(x => x.Code).NotEmpty().MaximumLength(50);

        RuleFor(x => x.AppliesTo)
            .NotEmpty()
            .Must(CancellationActor.IsValid)
            .WithMessage("applies_to must be one of: customer, nurse, admin.");

        RuleFor(x => x.RefundPercentage).InclusiveBetween(0m, 100m);
        RuleFor(x => x.FeeAmountIrr).GreaterThanOrEqualTo(0);
        RuleFor(x => x.FeeRate).InclusiveBetween(0m, 1m).When(x => x.FeeRate.HasValue);

        RuleFor(x => x)
            .Must(x => x.HoursBeforeStartMin is null || x.HoursBeforeStartMax is null || x.HoursBeforeStartMin < x.HoursBeforeStartMax)
            .WithMessage("hours_before_start_min must be less than hours_before_start_max.");
    }
}
