using FluentValidation;
using AdsTrackingService.API.Application.Commands;

namespace AdsTrackingService.API.Application.Validations;

/// <summary>
/// EN: Validator for TrackPixelEventCommand.
/// VI: Validator cho TrackPixelEventCommand.
/// </summary>
public class TrackPixelEventCommandValidator : AbstractValidator<TrackPixelEventCommand>
{
    public TrackPixelEventCommandValidator()
    {
        RuleFor(x => x.PixelCode)
            .NotEmpty()
            .WithMessage("Pixel code is required / Mã pixel là bắt buộc")
            .MaximumLength(100)
            .WithMessage("Pixel code max 100 characters / Mã pixel tối đa 100 ký tự");

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

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

        RuleFor(x => x.EventType)
            .IsInEnum()
            .WithMessage("Event type is invalid / Loại sự kiện không hợp lệ");

        RuleFor(x => x.UserAgent)
            .MaximumLength(500)
            .When(x => x.UserAgent != null)
            .WithMessage("User agent max 500 characters / User agent tối đa 500 ký tự");

        RuleFor(x => x.IpAddress)
            .MaximumLength(45)
            .When(x => x.IpAddress != null)
            .WithMessage("IP address max 45 characters / Địa chỉ IP tối đa 45 ký tự");
    }
}
