using FluentValidation; using SeaHaven.Services.DTOs; namespace SeaHaven.Services.Validation { public interface ICreatePMScheduleValidation : IValidator { } public class CreatePMScheduleValidation : AbstractValidator, ICreatePMScheduleValidation { public CreatePMScheduleValidation() { RuleFor(x => x.Name) .NotEmpty().WithMessage("PM Schedule name is required") .MaximumLength(200).WithMessage("Name cannot exceed 200 characters"); RuleFor(x => x.Frequency) .NotEmpty().WithMessage("Frequency is required"); RuleFor(x => x.StartDate) .NotEmpty().WithMessage("Start date is required") .LessThanOrEqualTo(DateTime.Now.AddYears(1)) .WithMessage("Start date cannot be more than 1 year in the future"); RuleFor(x => x.AssetId) .GreaterThan(0).WithMessage("Valid asset must be selected") .When(x => x.AssetId.HasValue); RuleFor(x => x.LocationId) .GreaterThan(0).WithMessage("Valid location must be selected") .When(x => x.LocationId.HasValue); } } public interface IUpdatePMScheduleValidation : IValidator { } public class UpdatePMScheduleValidation : AbstractValidator, IUpdatePMScheduleValidation { public UpdatePMScheduleValidation() { RuleFor(x => x.Name) .MaximumLength(200).WithMessage("Name cannot exceed 200 characters") .When(x => !string.IsNullOrEmpty(x.Name)); RuleFor(x => x.StartDate) .LessThanOrEqualTo(DateTime.Now.AddYears(1)) .When(x => x.StartDate.HasValue) .WithMessage("Start date cannot be more than 1 year in the future"); RuleFor(x => x.AssetId) .GreaterThan(0).WithMessage("Valid asset must be selected") .When(x => x.AssetId.HasValue); RuleFor(x => x.LocationId) .GreaterThan(0).WithMessage("Valid location must be selected") .When(x => x.LocationId.HasValue); } } }