namespace LiteCharms.Features.Utilities.Commands; public class SendEmailCommand : IRequest { public string? From { get; set; } public string? SenderName { get; set; } public string? To { get; set; } public string? RecipientName { get; set; } public string? Subject { get; set; } public string? Message { get; set; } public bool IsHtml { get; set; } public Stream? Attachment { get; set; } public string? AttachmentFileName { get; set; } private SendEmailCommand(string from, string senderName, string to, string recipientName, string subject, string message, bool isHtml = false, Stream? attachment = null, string? attachmentFileName = null) { From = from; To = to; Subject = subject; Message = message; IsHtml = isHtml; Attachment = attachment; AttachmentFileName = attachmentFileName; SenderName = senderName; RecipientName = recipientName; } public static SendEmailCommand Create(string from, string senderName, string to, string recipientName, string subject, string message, bool isHtml = false, Stream? attachment = null, string? attachmentFileName = null) { if (string.IsNullOrWhiteSpace(from)) throw new ArgumentException("From address cannot be null or empty.", nameof(from)); if (string.IsNullOrWhiteSpace(senderName)) throw new ArgumentException("Sender name cannot be null or empty.", nameof(senderName)); if (!string.IsNullOrWhiteSpace(senderName) && senderName?.Length > 255) throw new ArgumentException("Sender name cannot exceed 255 characters.", nameof(senderName)); if (string.IsNullOrWhiteSpace(to)) throw new ArgumentException("To address cannot be null or empty.", nameof(to)); if (string.IsNullOrWhiteSpace(recipientName)) throw new ArgumentException("Recipient name cannot be null or empty.", nameof(recipientName)); if (!string.IsNullOrWhiteSpace(recipientName) && recipientName?.Length > 255) throw new ArgumentException("Recipient name cannot exceed 255 characters.", nameof(recipientName)); if (string.IsNullOrWhiteSpace(subject)) throw new ArgumentException("Subject cannot be null or empty.", nameof(subject)); if (!string.IsNullOrWhiteSpace(subject) && subject?.Length > 2048) throw new ArgumentException("Subject cannot exceed 2048 characters.", nameof(subject)); if (string.IsNullOrWhiteSpace(message)) throw new ArgumentException("Message cannot be null or empty.", nameof(message)); if (message.Length > 10485760) throw new ArgumentException("Message cannot exceed 10 MB.", nameof(message)); if (attachment != null && string.IsNullOrWhiteSpace(attachmentFileName)) throw new ArgumentException("Attachment file name must be provided when an attachment is included.", nameof(attachmentFileName)); if (attachment is not null && attachment.Length > 10485760) throw new ArgumentException("Attachment cannot exceed 10 MB.", nameof(attachment)); if (!string.IsNullOrWhiteSpace(attachmentFileName) && attachmentFileName.Length > 255) throw new ArgumentException("Attachment file name cannot exceed 255 characters.", nameof(attachmentFileName)); return new(from, senderName!, to, recipientName!, subject!, message, isHtml, attachment, attachmentFileName); } }