using FluentValidation; using SeaHaven.Services.DTOs; namespace SeaHaven.Services.Validation { public interface ICreateEmployeeValidation : IValidator { } public class CreateEmployeeValidation : AbstractValidator, ICreateEmployeeValidation { public CreateEmployeeValidation() { 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) .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.DepartmentId) .GreaterThan(0).WithMessage("Valid department must be selected") .When(x => x.DepartmentId.HasValue); RuleFor(x => x.JobTitleId) .GreaterThan(0).WithMessage("Valid job title must be selected") .When(x => x.JobTitleId.HasValue); RuleFor(x => x.RegionId) .GreaterThan(0).WithMessage("Valid region must be selected") .When(x => x.RegionId.HasValue); } } public interface IUpdateEmployeeValidation : IValidator { } public class UpdateEmployeeValidation : AbstractValidator, IUpdateEmployeeValidation { public UpdateEmployeeValidation() { 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.DepartmentId) .GreaterThan(0).WithMessage("Valid department must be selected") .When(x => x.DepartmentId.HasValue); RuleFor(x => x.JobTitleId) .GreaterThan(0).WithMessage("Valid job title must be selected") .When(x => x.JobTitleId.HasValue); RuleFor(x => x.RegionId) .GreaterThan(0).WithMessage("Valid region must be selected") .When(x => x.RegionId.HasValue); } } }