using GB5Shared.ListQuery; namespace SwDAL.DTO.DdlScript; // ── Main entity DTO ──────────────────────────────────────────────────────── public class DdlScriptDTO { public int DdlScriptId { get; set; } public int DbModelId { get; set; } public string? DbModelName { get; set; } public int BranchId { get; set; } public string? BranchCode { get; set; } public string BranchName { get; set; } public int ObjectGroupId { get; set; } = -1; public string ObjectGroupCode { get; set; } public string ObjectGroupName { get; set; } public byte ObjectType { get; set; } = 0; public string SchemaName { get; set; } = "dbo"; public string ObjectName { get; set; } = string.Empty; public string SqlScript { get; set; } = string.Empty; public string? RollbackSql { get; set; } public string? Checksum { get; set; } public byte ScriptStatus { get; set; } = 0; public bool ApprovalRequired { get; set; } public int ApprovedById { get; set; } = -1; public DateTime? ApprovedOn { get; set; } public short Sequence { get; set; } = 0; // Standard M-table fields public short Version { get; set; } public byte Status { get; set; } = 1; public short SortOrder { get; set; } = 9999; public int CreatedById { get; set; } public DateTime CreatedOn { get; set; } public int ModifiedById { get; set; } public DateTime ModifiedOn { get; set; } public byte SourceType { get; set; } = 5; public int TenantId { get; set; } // Nullable — a freshly-generated Draft script (e.g. RefDataSourceBLL's own output) legitimately // has no Change Request yet; SW.MSWDDLSCRIPT.CHANGEREQUESTID is a nullable FK to // SW.MSWCHANGEREQUEST for exactly this reason. A non-nullable int here would default to 0 and // violate FK_MSWDDLSCRIPT_CR on every brand-new, not-yet-attached script (confirmed live). public int? ChangeRequestId { get; set; } } // ── Picklist DTO ─────────────────────────────────────────────────────────── public class DdlScriptPickListDTO { public int DdlScriptId { get; set; } public string ObjectName { get; set; } = string.Empty; } // ── Execution log DTO (for LogExecutionAsync insert) ────────────────────── public class DdlExecutionLogDTO { public int DdlScriptId { get; set; } public int ClientDbId { get; set; } public byte ExecStatus { get; set; } public string? ErrorMessage { get; set; } public DateTime ExecutedOn { get; set; } public int CreatedById { get; set; } public DateTime CreatedOn { get; set; } public int TenantId { get; set; } } // ── List infrastructure ──────────────────────────────────────────────────── public sealed class DdlScriptListCriteria : ICriteria { [CriteriaField("ouid")] public int? OUId { get; set; } [CriteriaField("branchid")] public int? BranchId { get; set; } [CriteriaField("dbmodelid")] public int? DbModelId { get; set; } [CriteriaField("scriptstatus")] public byte? ScriptStatus { get; set; } [CriteriaField("searchtext")] public string? SearchText { get; set; } [CriteriaField("sortby")] public string? SortBy { get; set; } [CriteriaField("sortdesc")] public bool SortDesc { get; set; } [CriteriaField("pagesize")] public int PageSize { get; set; } = 100; [CriteriaField("pageoffset")] public int PageOffset { get; set; } = 0; } public sealed record DdlScriptListQuery(DdlScriptListCriteria Criteria) : IListQuery; public sealed class DdlScriptListDTO { public int DdlScriptId { get; set; } public string ObjectName { get; set; } = string.Empty; public string SchemaName { get; set; } = string.Empty; public byte ScriptStatus { get; set; } public int BranchId { get; set; } public int TotalCount { get; set; } }