using FluentValidation; using SeaHaven.Services.DTOs; namespace SeaHaven.Services.Validation { public interface ICreateContactValidation : IValidator { } public class CreateContactValidation : AbstractValidator, ICreateContactValidation { public CreateContactValidation() { RuleFor(x => x.FirstName) .NotEmpty().WithMessage("First name is required") .MaximumLength(100).WithMessage("First name cannot exceed 100 characters"); RuleFor(x => x.LastName) .NotEmpty().WithMessage("Last name is required") .MaximumLength(100).WithMessage("Last name cannot exceed 100 characters"); RuleFor(x => x.Email) .NotEmpty().WithMessage("Email is required") .EmailAddress().WithMessage("Invalid email address"); RuleFor(x => x.Phone) .MaximumLength(20).WithMessage("Phone number cannot exceed 20 characters") .When(x => !string.IsNullOrEmpty(x.Phone)); RuleFor(x => x.Mobile) .MaximumLength(20).WithMessage("Mobile number cannot exceed 20 characters") .When(x => !string.IsNullOrEmpty(x.Mobile)); RuleFor(x => x.AccountId) .GreaterThan(0).WithMessage("Valid account must be selected") .When(x => x.AccountId.HasValue); } } public interface IUpdateContactValidation : IValidator { } public class UpdateContactValidation : AbstractValidator, IUpdateContactValidation { public UpdateContactValidation() { RuleFor(x => x.FirstName) .MaximumLength(100).WithMessage("First name cannot exceed 100 characters") .When(x => !string.IsNullOrEmpty(x.FirstName)); RuleFor(x => x.LastName) .MaximumLength(100).WithMessage("Last name cannot exceed 100 characters") .When(x => !string.IsNullOrEmpty(x.LastName)); RuleFor(x => x.Email) .EmailAddress().WithMessage("Invalid email address") .When(x => !string.IsNullOrEmpty(x.Email)); RuleFor(x => x.Phone) .MaximumLength(20).WithMessage("Phone number cannot exceed 20 characters") .When(x => !string.IsNullOrEmpty(x.Phone)); RuleFor(x => x.Mobile) .MaximumLength(20).WithMessage("Mobile number cannot exceed 20 characters") .When(x => !string.IsNullOrEmpty(x.Mobile)); RuleFor(x => x.AccountId) .GreaterThan(0).WithMessage("Valid account must be selected") .When(x => x.AccountId.HasValue); } } }