namespace WalletService.API.Application.Validations;

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

/// <summary>
/// EN: Validator for CreatePaymentCommand.
/// VI: Validator cho CreatePaymentCommand.
/// </summary>
public class CreatePaymentCommandValidator : AbstractValidator<CreatePaymentCommand>
{
    public CreatePaymentCommandValidator()
    {
        RuleFor(x => x.OrderId)
            .NotEmpty()
            .WithMessage("Order ID is required / Ma don hang la bat buoc");

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

        RuleFor(x => x.Currency)
            .NotEmpty()
            .WithMessage("Currency is required / Tien te la bat buoc")
            .MaximumLength(10)
            .WithMessage("Currency code must not exceed 10 characters / Ma tien te khong vuot qua 10 ky tu");

        RuleFor(x => x.GatewayName)
            .NotEmpty()
            .WithMessage("Gateway name is required / Ten cong thanh toan la bat buoc")
            .MaximumLength(50)
            .WithMessage("Gateway name must not exceed 50 characters / Ten cong thanh toan khong vuot qua 50 ky tu");

        RuleFor(x => x.ReturnUrl)
            .NotEmpty()
            .WithMessage("Return URL is required / URL tra ve la bat buoc")
            .Must(url => Uri.TryCreate(url, UriKind.Absolute, out _))
            .WithMessage("Return URL must be a valid URL / URL tra ve phai hop le");

        RuleFor(x => x.IpAddress)
            .NotEmpty()
            .WithMessage("IP address is required / Dia chi IP la bat buoc");
    }
}

/// <summary>
/// EN: Validator for ProcessPaymentCallbackCommand.
/// VI: Validator cho ProcessPaymentCallbackCommand.
/// </summary>
public class ProcessPaymentCallbackCommandValidator : AbstractValidator<ProcessPaymentCallbackCommand>
{
    public ProcessPaymentCallbackCommandValidator()
    {
        RuleFor(x => x.GatewayName)
            .NotEmpty()
            .WithMessage("Gateway name is required / Ten cong thanh toan la bat buoc");

        RuleFor(x => x.Parameters)
            .NotNull()
            .WithMessage("Callback parameters are required / Cac tham so callback la bat buoc")
            .Must(p => p.Count > 0)
            .WithMessage("Callback parameters cannot be empty / Cac tham so callback khong duoc trong");
    }
}
