using FluentValidation;
using AdsBillingService.API.Application.Commands;

namespace AdsBillingService.API.Application.Validations;

/// <summary>
/// EN: Validator for ChargeAdvertiserCommand.
/// VI: Validator cho ChargeAdvertiserCommand.
/// </summary>
public class ChargeAdvertiserCommandValidator : AbstractValidator<ChargeAdvertiserCommand>
{
    private static readonly string[] ValidChargeTypes = ["impression", "click"];

    public ChargeAdvertiserCommandValidator()
    {
        RuleFor(x => x.AdvertiserId)
            .NotEmpty()
            .WithMessage("Advertiser ID is required / Advertiser ID là bắt buộc");

        RuleFor(x => x.CampaignId)
            .NotEmpty()
            .WithMessage("Campaign ID is required / Campaign ID là bắt buộc");

        RuleFor(x => x.AdId)
            .NotEmpty()
            .WithMessage("Ad ID is required / Ad ID là bắt buộc");

        RuleFor(x => x.ChargeType)
            .NotEmpty()
            .WithMessage("Charge type is required / Loại charge là bắt buộc")
            .Must(ct => ValidChargeTypes.Contains(ct))
            .WithMessage("Charge type must be 'impression' or 'click' / Loại charge phải là 'impression' hoặc 'click'");

        RuleFor(x => x.Amount)
            .GreaterThan(0)
            .WithMessage("Amount must be greater than 0 / Số tiền phải lớn hơn 0");
    }
}
