using FluentValidation;
using FacebookService.API.Application.Commands;

namespace FacebookService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreateCustomerCommand.
/// VI: Validator cho CreateCustomerCommand.
/// </summary>
public class CreateCustomerCommandValidator : AbstractValidator<CreateCustomerCommand>
{
    public CreateCustomerCommandValidator()
    {
        RuleFor(x => x.FacebookUserId)
            .NotEmpty()
            .WithMessage("Facebook User ID is required / Facebook User ID là bắt buộc")
            .MaximumLength(50)
            .WithMessage("Facebook User ID must be less than 50 characters / Facebook User ID phải ít hơn 50 ký tự");

        RuleFor(x => x.Name)
            .MaximumLength(255)
            .WithMessage("Name must be less than 255 characters / Tên phải ít hơn 255 ký tự")
            .When(x => x.Name != null);

        RuleFor(x => x.Email)
            .EmailAddress()
            .WithMessage("Email format is invalid / Định dạng email không hợp lệ")
            .MaximumLength(255)
            .WithMessage("Email must be less than 255 characters / Email phải ít hơn 255 ký tự")
            .When(x => !string.IsNullOrEmpty(x.Email));

        RuleFor(x => x.Phone)
            .MaximumLength(50)
            .WithMessage("Phone must be less than 50 characters / Số điện thoại phải ít hơn 50 ký tự")
            .When(x => x.Phone != null);
    }
}
