using DigitalData.EmailProfiler.Application.EmailProcessing.Commands; using FluentValidation; namespace DigitalData.EmailProfiler.Application.EmailProcessing.Validators; /// /// Validator for ProcessEmailCommand. /// public class ProcessEmailCommandValidator : AbstractValidator { public ProcessEmailCommandValidator() { RuleFor(x => x.ProfileId) .GreaterThan(0).WithMessage("Profile ID must be greater than 0"); RuleFor(x => x.MessageId) .NotEmpty().WithMessage("Message ID is required") .MaximumLength(500).WithMessage("Message ID must not exceed 500 characters"); RuleFor(x => x.Sender) .NotEmpty().WithMessage("Sender is required") .MaximumLength(200).WithMessage("Sender must not exceed 200 characters") .EmailAddress().WithMessage("Sender must be a valid email address"); RuleFor(x => x.Subject) .NotEmpty().WithMessage("Subject is required") .MaximumLength(500).WithMessage("Subject must not exceed 500 characters"); RuleFor(x => x.ReceivedDate) .NotEmpty().WithMessage("Received date is required") .LessThanOrEqualTo(DateTime.Now.AddDays(1)).WithMessage("Received date cannot be in the future"); RuleFor(x => x.Attachments) .NotNull().WithMessage("Attachments collection cannot be null"); RuleForEach(x => x.Attachments).ChildRules(attachment => { attachment.RuleFor(a => a.FileName) .NotEmpty().WithMessage("Attachment file name is required") .MaximumLength(500).WithMessage("Attachment file name must not exceed 500 characters"); attachment.RuleFor(a => a.Content) .NotEmpty().WithMessage("Attachment content is required"); attachment.RuleFor(a => a.SizeBytes) .GreaterThan(0).WithMessage("Attachment size must be greater than 0") .LessThanOrEqualTo(100 * 1024 * 1024).WithMessage("Attachment size must not exceed 100 MB"); }); } }