using BookHive.DTO.Member;
using FastEndpoints;
using FluentValidation;

namespace BookHive.Validators.Members;

public class CreateMemberDtoValidator : Validator<CreateMemberDto>
{
    public CreateMemberDtoValidator()
    {
        RuleFor(x => x.Email)
            .NotEmpty()
            .WithMessage("Email is required.")
            .EmailAddress()
            .WithMessage("Email is invalid.")
            .MaximumLength(255)
            .WithMessage("Email cannot be longer than 255 characters.");

        RuleFor(x => x.FirstName)
            .NotEmpty()
            .WithMessage("First name is required.")
            .MaximumLength(100)
            .WithMessage("First name cannot be longer than 100 characters.")
            .MinimumLength(2)
            .WithMessage("First name cannot be shorter than 2 characters.");

        RuleFor(x => x.LastName)
            .NotEmpty()
            .WithMessage("Last name is required.")
            .MaximumLength(100)
            .WithMessage("Last name cannot be longer than 100 characters.")
            .MinimumLength(2)
            .WithMessage("Last name cannot be shorter than 2 characters.");

        RuleFor(x => x.MembershipDate)
            .NotEmpty()
            .WithMessage("Membership date is required.")
            .Must(d => d <= DateOnly.FromDateTime(DateTime.Now))
            .WithMessage("Membership date cannot be in the future.");
    }
}