using FluentValidation;
using AdsManagerService.API.Application.Commands;

namespace AdsManagerService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreateAdCommand.
/// VI: Validator cho CreateAdCommand.
/// </summary>
public class CreateAdCommandValidator : AbstractValidator<CreateAdCommand>
{
    private static readonly string[] ValidFormats = ["single_image", "single_video", "carousel", "collection", "stories"];

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

        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Ad name is required / Tên quảng cáo là bắt buộc")
            .MaximumLength(200)
            .WithMessage("Ad name max 200 characters / Tên quảng cáo tối đa 200 ký tự");

        RuleFor(x => x.Format)
            .NotEmpty()
            .WithMessage("Ad format is required / Định dạng quảng cáo là bắt buộc")
            .Must(f => ValidFormats.Contains(f))
            .WithMessage("Invalid format. Must be one of: single_image, single_video, carousel, collection, stories / Định dạng không hợp lệ");

        RuleFor(x => x.Headline)
            .MaximumLength(100)
            .When(x => x.Headline != null)
            .WithMessage("Headline max 100 characters / Tiêu đề tối đa 100 ký tự");

        RuleFor(x => x.PrimaryText)
            .MaximumLength(500)
            .When(x => x.PrimaryText != null)
            .WithMessage("Primary text max 500 characters / Nội dung chính tối đa 500 ký tự");

        RuleFor(x => x.CallToAction)
            .MaximumLength(50)
            .When(x => x.CallToAction != null)
            .WithMessage("Call to action max 50 characters / Lời kêu gọi tối đa 50 ký tự");

        RuleFor(x => x.DestinationUrl)
            .MaximumLength(2000)
            .When(x => x.DestinationUrl != null)
            .WithMessage("Destination URL max 2000 characters / URL đích tối đa 2000 ký tự");

        RuleFor(x => x.CreativeUrl)
            .MaximumLength(2000)
            .When(x => x.CreativeUrl != null)
            .WithMessage("Creative URL max 2000 characters / URL sáng tạo tối đa 2000 ký tự");
    }
}
