using FluentValidation;
using IamService.API.Application.Commands.Verifications;

namespace IamService.API.Application.Validations;

/// <summary>
/// EN: Validator for RequestPhoneVerificationCommand.
/// VI: Validator cho RequestPhoneVerificationCommand.
/// </summary>
public class RequestPhoneVerificationCommandValidator : AbstractValidator<RequestPhoneVerificationCommand>
{
    public RequestPhoneVerificationCommandValidator()
    {
        RuleFor(x => x.UserId)
            .NotEmpty().WithMessage("User ID is required");

        RuleFor(x => x.PhoneNumber)
            .NotEmpty().WithMessage("Phone number is required")
            .Matches(@"^\+?[1-9]\d{6,14}$").WithMessage("Invalid phone number format. Use international format like +84912345678");
    }
}

/// <summary>
/// EN: Validator for RequestEmailVerificationCommand.
/// VI: Validator cho RequestEmailVerificationCommand.
/// </summary>
public class RequestEmailVerificationCommandValidator : AbstractValidator<RequestEmailVerificationCommand>
{
    public RequestEmailVerificationCommandValidator()
    {
        RuleFor(x => x.UserId)
            .NotEmpty().WithMessage("User ID is required");

        RuleFor(x => x.Email)
            .NotEmpty().WithMessage("Email is required")
            .EmailAddress().WithMessage("Invalid email format");
    }
}

/// <summary>
/// EN: Validator for ConfirmVerificationCommand.
/// VI: Validator cho ConfirmVerificationCommand.
/// </summary>
public class ConfirmVerificationCommandValidator : AbstractValidator<ConfirmVerificationCommand>
{
    public ConfirmVerificationCommandValidator()
    {
        RuleFor(x => x.VerificationId)
            .NotEmpty().WithMessage("Verification ID is required");

        RuleFor(x => x.Code)
            .NotEmpty().WithMessage("Verification code is required")
            .Length(6).WithMessage("Verification code must be 6 digits")
            .Matches(@"^\d{6}$").WithMessage("Verification code must contain only digits");
    }
}
