// EN: Validators for Point commands (earn, spend, create account).
// VI: Validators cho cac commands Point (tich diem, tieu diem, tao tai khoan).

using FluentValidation;
using WalletService.API.Application.Commands;

namespace WalletService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreatePointAccountCommand.
/// VI: Validator cho CreatePointAccountCommand.
/// </summary>
public class CreatePointAccountCommandValidator : AbstractValidator<CreatePointAccountCommand>
{
    public CreatePointAccountCommandValidator()
    {
        RuleFor(x => x.UserId)
            .NotEmpty()
            .WithMessage("User ID is required / User ID la bat buoc");
    }
}

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

        RuleFor(x => x.Points)
            .GreaterThan(0)
            .WithMessage("Points must be greater than zero / Diem phai lon hon 0");

        RuleFor(x => x.Source)
            .NotEmpty()
            .WithMessage("Source is required / Nguon la bat buoc")
            .MaximumLength(100)
            .WithMessage("Source must not exceed 100 characters / Nguon khong vuot qua 100 ky tu");

        RuleFor(x => x.Description)
            .NotEmpty()
            .WithMessage("Description is required / Mo ta la bat buoc")
            .MaximumLength(500)
            .WithMessage("Description must not exceed 500 characters / Mo ta khong vuot qua 500 ky tu");

        RuleFor(x => x.ExpiryMonths)
            .GreaterThan(0)
            .WithMessage("Expiry months must be greater than zero / So thang het han phai lon hon 0")
            .LessThanOrEqualTo(120)
            .WithMessage("Expiry months must not exceed 120 / So thang het han khong vuot qua 120")
            .When(x => x.ExpiryMonths.HasValue);
    }
}

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

        RuleFor(x => x.Points)
            .GreaterThan(0)
            .WithMessage("Points must be greater than zero / Diem phai lon hon 0");

        RuleFor(x => x.Source)
            .NotEmpty()
            .WithMessage("Source is required / Nguon la bat buoc")
            .MaximumLength(100)
            .WithMessage("Source must not exceed 100 characters / Nguon khong vuot qua 100 ky tu");

        RuleFor(x => x.Description)
            .NotEmpty()
            .WithMessage("Description is required / Mo ta la bat buoc")
            .MaximumLength(500)
            .WithMessage("Description must not exceed 500 characters / Mo ta khong vuot qua 500 ky tu");
    }
}
