using System.Text.Json.Serialization;
namespace qdr.app.studiou.orders2printpack.EmailStorage
{
///
/// Root metadata container that holds information about the overall processing system
/// and maintains a collection of individual email items. This is the main data structure
/// that gets serialized to/from the metadata.json file.
///
public class Metadata
{
///
/// Timestamp when this metadata file was first created.
/// This helps track the age of the processing batch and provides audit information.
///
[JsonRequired]
[JsonPropertyName("metadata-created")]
public DateTime Created { get; set; } = DateTime.Now;
///
/// Timestamp of the last modification to this metadata.
/// Updated whenever items are added, removed, or their state changes.
/// Null when no modifications have been made since creation.
///
[JsonPropertyName("metadata-modified")]
public DateTime? Modified { get; set; } = null;
///
/// Collection of individual email items being processed.
/// Each item represents one recipient with their associated files and processing state.
///
[JsonRequired]
[JsonPropertyName("items")]
public List Items { get; set; } = new List();
}
///
/// Represents a single email item with all associated processing information.
/// Contains details about the recipient, files, processing state, and email content.
/// This is the core data structure that tracks each individual email through the workflow.
///
public class MetadataItem
{
#region Directory and File Information
///
/// Name of the directory containing files for this email item.
/// Typically matches or is derived from the recipient's email address.
/// Used to locate the source files for processing.
///
[JsonPropertyName("directory-name")]
[JsonRequired]
public string DirectoryName { get; set; } = string.Empty;
///
/// Current processing state of this email item.
/// Tracks progression through Ready -> Processing -> Uploading -> Sending -> Sent.
/// Can also be Error if something goes wrong.
///
[JsonPropertyName("state")]
[JsonRequired]
public EmailStateEnum State { get; set; } = EmailStateEnum.Ready;
#endregion
#region Recipient Information
///
/// Email address of the recipient who will receive the processed files.
/// This is the primary identifier for the email item.
///
[JsonPropertyName("email-address")]
[JsonRequired]
public string EmailAddress { get; set; } = string.Empty;
#endregion
#region Email Content
///
/// Subject line for the email that will be sent to the recipient.
/// Initially populated from the email template, may be personalized during processing.
///
[JsonPropertyName("subject")]
[JsonRequired]
public string Subject { get; set; } = string.Empty;
///
/// Body content of the email in HTML or plain text format.
/// Initially from template, gets personalized with download links, passwords, etc.
///
[JsonPropertyName("body")]
[JsonRequired]
public string Body { get; set; } = string.Empty;
#endregion
#region File and Attachment Information
///
/// Filename of the compressed attachment that will be uploaded and sent.
/// Generated during processing and includes timestamp for uniqueness.
/// Example: "studioufoto_user_at_example_dot_com_20240530_143022.zip"
///
[JsonPropertyName("attachment")]
[JsonRequired]
public string FileNameAttachment { get; set; } = string.Empty;
///
/// Size of the compressed attachment file in bytes.
/// Populated after compression is complete, used for upload progress tracking.
///
[JsonPropertyName("attachment-size")]
[JsonRequired]
public int SizeAttachment { get; set; } = 0;
///
/// Number of individual files (typically JPG images) contained within the compressed attachment.
/// Derived from scanning the source directory during metadata update.
///
[JsonPropertyName("attachment-content-count")]
[JsonRequired]
public int InternalFilesCount { get; set; } = 0;
#endregion
#region Business Logic
///
/// Comma-separated list of order numbers extracted from the filenames.
/// Used for business reference and included in email communications.
/// Example: "1001,1002,1003" extracted from files like "1001_photo1.jpg", "1002_photo1.jpg"
///
[JsonPropertyName("orders")]
[JsonRequired]
public string Orders { get; set; } = string.Empty;
#endregion
#region Upload and Download Information
///
/// Permanent link URL where the recipient can download their files.
/// Generated by the Temporary Shared Storage service after successful upload.
/// This link is included in the email sent to the recipient.
///
[JsonPropertyName("upload-permalink")]
public string UploadPermalink { get; set; } = string.Empty;
///
/// Password required to access the download link.
/// Generated during upload process for security.
/// Included in the email so recipient can access their files.
///
[JsonPropertyName("download-password")]
public string DownloadPassword { get; set; } = string.Empty;
#endregion
#region Audit and Tracking
///
/// Timestamp when this item completed processing (compression and upload).
/// Null until processing is complete, used for audit and performance tracking.
///
[JsonPropertyName("processed-date")]
public DateTime? ProcessedDate { get; set; }
///
/// Timestamp when the email was successfully sent to the recipient.
/// Null until email sending is complete, marks final completion of the workflow.
///
[JsonPropertyName("sent-date")]
public DateTime? SentDate { get; set; }
///
/// Error message if processing failed at any stage.
/// Null when no errors have occurred, populated when State is set to Error.
/// Used for debugging and manual intervention.
///
[JsonPropertyName("error-message")]
public string? ErrorMessage { get; set; }
#endregion
}
}