using FluentValidation;
using SIGCM2.Application.Auth;

namespace SIGCM2.Application.Usuarios.ChangeMyPassword;

public sealed class ChangeMyPasswordCommandValidator : AbstractValidator<ChangeMyPasswordCommand>
{
    public ChangeMyPasswordCommandValidator(AuthOptions authOptions)
    {
        RuleFor(x => x.OldPassword)
            .NotEmpty()
            .WithMessage("La contraseña actual es requerida.");

        RuleFor(x => x.NewPassword)
            .NotEmpty()
            .WithMessage("La nueva contraseña es requerida.")
            .MinimumLength(authOptions.PasswordMinLength)
            .WithMessage($"La contraseña debe tener al menos {authOptions.PasswordMinLength} caracteres.");

        if (authOptions.PasswordRequireLetter)
        {
            RuleFor(x => x.NewPassword)
                .Matches(@"[a-zA-Z]")
                .WithMessage("La contraseña debe contener al menos una letra.");
        }

        if (authOptions.PasswordRequireDigit)
        {
            RuleFor(x => x.NewPassword)
                .Matches(@"\d")
                .WithMessage("La contraseña debe contener al menos un dígito.");
        }
    }
}
