using GB5Shared.DTO.Framework.Login; namespace GB5Shared.DTO.ECM { using Guid = System.Guid; // ── Enum ──────────────────────────────────────────────────── // Matches actual TATTACHMENT.ATTACHMENTOPTION CHECK constraint: // 0=ALFRESCO, 1=FILENET, 2=AMAZON S3, 3=FILE BASED public enum AttachmentOptionType { Alfresco = 0, Filenet = 1, AmazonS3 = 2, FileBased = 3 } // ── Upload Request / Response ──────────────────────────────── public class AttachmentUploadRequest { /// Links to MDOCUMENTSETDETAIL — determines templates, document type, etc. public int DocumentSetDetailId { get; set; } /// OBJECTTYPEID — FK to MENTITY(ENTITYID). Identifies the entity type. public int ObjectTypeId { get; set; } /// 0 when uploading before entity save (Phase 1). Real PK when entity exists. public int ObjectId { get; set; } public int BizTransactionTypeId { get; set; } = -1; /// FE-generated UUID. Used as folder placeholder in Phase 1. public Guid RowGuid { get; set; } /// /// Entity-specific context values for dynamic token resolution. /// e.g. { "poNumber": "PO-001", "vendor": { "vendorCode": "V001" } } /// public Dictionary ContextDictionary { get; set; } = new(); public string? Remarks { get; set; } public string Tags { get; set; } = string.Empty; public byte AttachmentType { get; set; } = 0; // 0=File, 1=Link } /// JSON-body counterpart to — carries the /// file as Base64 instead of multipart/form-data. public class AttachmentUploadBase64Request { public int DocumentSetDetailId { get; set; } public int ObjectTypeId { get; set; } public int ObjectId { get; set; } public int BizTransactionTypeId { get; set; } = -1; public Guid RowGuid { get; set; } public Dictionary ContextDictionary { get; set; } = new(); public string? Remarks { get; set; } public string Tags { get; set; } = string.Empty; public byte AttachmentType { get; set; } = 0; // 0=File, 1=Link public string FileName { get; set; } = string.Empty; public string ContentType { get; set; } = string.Empty; public string Base64Content { get; set; } = string.Empty; } public class AttachmentUploadResponse { public int AttachmentId { get; set; } public string DisplayFileName { get; set; } = string.Empty; public string FolderName { get; set; } = string.Empty; public string AttachedFileName { get; set; } = string.Empty; public long FileSizeBytes { get; set; } public bool IsDeferred { get; set; } public int Version { get; set; } public int SlNo { get; set; } } // ── Deferred Path Resolution (single-attachment "confirm" call) ─ /// /// Confirms a deferred attachment once the caller knows the field values its /// LOCATIONTEMPLATE/DOCUMENTNAMETEMPLATE tokens needed (e.g. {EMP}, {Year}, {Month}) /// and/or the real ObjectId. Re-resolves the template, moves the file in storage from /// its Phase-1 placeholder path to the final path, and updates TATTACHMENT. /// public class AttachmentResolvePathRequest { public int ObjectId { get; set; } public int AttachmentId { get; set; } public Guid RowGuid { get; set; } /// Arbitrary field values now known (e.g. {"EMP":"E498","Year":"2026","Month":"08"}) — /// merged into the template's ContextDictionary for token resolution. public Dictionary PostDataObject { get; set; } = new(); } public class AttachmentResolvePathResponse { public int AttachmentId { get; set; } public int ObjectId { get; set; } public string FolderName { get; set; } = string.Empty; public string AttachedFileName { get; set; } = string.Empty; public string DisplayFileName { get; set; } = string.Empty; /// True when this call was a no-op retry — the attachment was already /// resolved to this exact path by a prior call. public bool AlreadyResolved { get; set; } } /// Raw TATTACHMENT row loaded to (re)resolve its path. internal sealed class AttachmentResolveRow { public int AttachmentId { get; set; } public int ObjectId { get; set; } public int ObjectTypeId { get; set; } public int BizTransactionTypeId { get; set; } public int DocumentSetDetailId { get; set; } public short SlNo { get; set; } public short Version { get; set; } public string CmsId { get; set; } = string.Empty; public string FolderName { get; set; } = string.Empty; public string AttachedFileName { get; set; } = string.Empty; public string DisplayFileName { get; set; } = string.Empty; public byte IsPathDeferred { get; set; } public byte AttachmentOption { get; set; } public DateTime CreatedOn { get; set; } } // ── Template Resolution Context ────────────────────────────── /// All input needed to resolve attachment paths at upload time. public class AttachmentResolutionContext { public LoginDTO Login { get; set; } = null!; public int ObjectTypeId { get; set; } // OBJECTTYPEID public int ObjectId { get; set; } // 0 in Phase 1 public Guid RowGuid { get; set; } public int BizTransactionTypeId { get; set; } public int DocumentSetDetailId { get; set; } public string FileExtension { get; set; } = string.Empty; /// Original uploaded filename without extension — resolvable as {FileName}. public string OriginalFileName { get; set; } = string.Empty; public int SlNo { get; set; } public int Version { get; set; } public DateTime UploadedOn { get; set; } = DateTime.UtcNow; public Dictionary ContextDictionary { get; set; } = new(); } /// Output of path resolution — all three TATTACHMENT path fields. public class ResolvedAttachmentPaths { public string FolderName { get; set; } = string.Empty; public string AttachedFileName { get; set; } = string.Empty; public string DisplayFileName { get; set; } = string.Empty; public string StorageKey { get; set; } = string.Empty; public bool IsDeferred { get; set; } } // ── Template Data (loaded from DB) ─────────────────────────── public class AttachmentTemplateData { public int DocumentSetDetailId { get; set; } public int DocumentSetId { get; set; } public string? LocationTemplate { get; set; } public string? DisplayNameTemplate { get; set; } public string? DocumentNameTemplate { get; set; } public string? TagFields { get; set; } public string? PropertyFields { get; set; } public int ModuleId { get; set; } public string DocumentSetCode { get; set; } = string.Empty; public string DocumentSetName { get; set; } = string.Empty; public int DocumentTypeId { get; set; } public string DocumentTypeCode { get; set; } = string.Empty; public string DocumentTypeName { get; set; } = string.Empty; public string ModuleCode { get; set; } = string.Empty; public string ModuleName { get; set; } = string.Empty; public byte IsVersion { get; set; } } // ── Phase 2 Deferred Path Resolution ──────────────────────── /// An attachment that needs Phase 2 path re-resolution (ISPATHDEFERRED=1). public class DeferredAttachment { public int AttachmentId { get; set; } public string RowGuidPlaceholder { get; set; } = string.Empty; public int NewObjectId { get; set; } public int ObjectTypeId { get; set; } public string OldCmsId { get; set; } = string.Empty; public string OldFolderName { get; set; } = string.Empty; public string OldAttachedFileName { get; set; } = string.Empty; public string DisplayFileName { get; set; } = string.Empty; public byte StorageAdapterType { get; set; } public short Version { get; set; } } /// Path movement computed by Phase 2 — ready for storage move and DB update. public class PathMovement { public int AttachmentId { get; set; } public string OldCmsId { get; set; } = string.Empty; public string NewFolderName { get; set; } = string.Empty; public string NewAttachedFileName { get; set; } = string.Empty; public string NewCmsId { get; set; } = string.Empty; public string NewDisplayFileName { get; set; } = string.Empty; } // ── Internal helpers ───────────────────────────────────────── public class SlNoVersionResult { public short NextSlNo { get; set; } public short NextVersion { get; set; } } }