using FluentValidation; using SeaHaven.Services.DTOs; namespace SeaHaven.Services.Validation { public interface ICreateVendorValidation : IValidator { } public class CreateVendorValidation : AbstractValidator, ICreateVendorValidation { public CreateVendorValidation() { RuleFor(x => x.Name) .NotEmpty().WithMessage("Vendor name is required") .MaximumLength(200).WithMessage("Vendor name cannot exceed 200 characters"); 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.Address) .MaximumLength(500).WithMessage("Address cannot exceed 500 characters") .When(x => !string.IsNullOrEmpty(x.Address)); RuleFor(x => x.City) .MaximumLength(100).WithMessage("City cannot exceed 100 characters") .When(x => !string.IsNullOrEmpty(x.City)); RuleFor(x => x.State) .MaximumLength(2).WithMessage("State must be 2 characters") .When(x => !string.IsNullOrEmpty(x.State)); RuleFor(x => x.Zipcode) .MaximumLength(10).WithMessage("Zipcode cannot exceed 10 characters") .When(x => !string.IsNullOrEmpty(x.Zipcode)); } } public interface IUpdateVendorValidation : IValidator { } public class UpdateVendorValidation : AbstractValidator, IUpdateVendorValidation { public UpdateVendorValidation() { RuleFor(x => x.Name) .MaximumLength(200).WithMessage("Vendor name cannot exceed 200 characters") .When(x => !string.IsNullOrEmpty(x.Name)); 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.Address) .MaximumLength(500).WithMessage("Address cannot exceed 500 characters") .When(x => !string.IsNullOrEmpty(x.Address)); RuleFor(x => x.City) .MaximumLength(100).WithMessage("City cannot exceed 100 characters") .When(x => !string.IsNullOrEmpty(x.City)); RuleFor(x => x.State) .MaximumLength(2).WithMessage("State must be 2 characters") .When(x => !string.IsNullOrEmpty(x.State)); RuleFor(x => x.Zipcode) .MaximumLength(10).WithMessage("Zipcode cannot exceed 10 characters") .When(x => !string.IsNullOrEmpty(x.Zipcode)); } } }