namespace TCMSDAL.DTO;
// ── Test Environment list / detail ───────────────────────────────────────────
///
/// Row returned by GetTestEnvironments — one per MSERVERCONFIG row where DBINSTANCETYPE=1.
///
public class TCMSTestEnvListDTO
{
public int ServerConfigId { get; set; }
public string ConnectionName { get; set; } = string.Empty;
public string DatabaseName { get; set; } = string.Empty;
public string ServerIP { get; set; } = string.Empty;
public string ServerName { get; set; } = string.Empty;
public int DatabaseType { get; set; } // 0=SQL, 1=Oracle, 2=PostgreSQL, 3=MySQL
public string DatabaseTypeText { get; set; } = string.Empty;
public string ControlSourceDb { get; set; } = string.Empty;
public int Status { get; set; }
public int DbInstanceType { get; set; } // always 1 (TEST) in this list
public DateTime? LastResetOn { get; set; }
public string? LastResetBy { get; set; }
public bool IsStale { get; set; } // true if CTRL was updated after last sync
}
///
/// Decrypted connection details returned by GetTestDbConnection.
/// Used by Cypress queryDb task to establish a direct test DB connection.
/// Only returned for DBINSTANCETYPE=1 (TEST) configs — never for LIVE.
///
public class TCMSTestDbConnectionDTO
{
public int ServerConfigId { get; set; }
public string ConnectionName { get; set; } = string.Empty;
public string ServerIP { get; set; } = string.Empty;
public string DatabaseName { get; set; } = string.Empty;
public int DatabaseType { get; set; } // 0=SQL, 1=Oracle, 2=PostgreSQL, 3=MySQL
public string UserName { get; set; } = string.Empty; // decrypted
public string Password { get; set; } = string.Empty; // decrypted
public string Port { get; set; } = string.Empty;
public int DbInstanceType { get; set; } // 1=TEST — used to guard against exposing LIVE configs
}
///
/// DTO for registering a new test run DB or cloning from a control copy.
///
public class TCMSRegisterTestDbDTO
{
public string ConnectionName { get; set; } = string.Empty;
public int ServerId { get; set; }
public string DatabaseName { get; set; } = string.Empty;
public int DatabaseType { get; set; } // 0=SQL, 1=Oracle, 2=PostgreSQL, 3=MySQL
public string DatabaseUserName { get; set; } = string.Empty;
public string DatabasePassword { get; set; } = string.Empty; // plaintext — BLL encrypts before insert
public string Port { get; set; } = string.Empty;
public string ControlSourceDbName{ get; set; } = string.Empty; // stored in CONTROLSOURCEDBNAME column
public int ClientId { get; set; }
public int ClientSiteId { get; set; }
}
///
/// Payload for Clone / Sync (Reset) operations.
///
public class TCMSCloneDbDTO
{
public string ControlDbName { get; set; } = string.Empty;
public string RunDbName { get; set; } = string.Empty;
public string ConnectionName { get; set; } = string.Empty; // MSERVERCONFIG.CONNECTIONNAME of the run copy
public string TriggeredBy { get; set; } = string.Empty; // UserId or 'CI-PIPELINE-{id}'
}
///
/// Payload for DB snapshot checkpoint operations.
///
public class TCMSSnapshotDTO
{
public int ServerConfigId { get; set; }
public string SnapshotName { get; set; } = string.Empty; // user-provided label
public string SnapshotDbName { get; set; } = string.Empty; // actual SQL Server snapshot DB name
public string SnapshotFilePath{ get; set; } = string.Empty; // .ss file path on server
public DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; } = string.Empty;
}
// ── Reset log ─────────────────────────────────────────────────────────────────
public class TCMSTestEnvResetLogDTO
{
public int ResetLogId { get; set; }
public int ServerConfigId { get; set; }
public string ConnectionName { get; set; } = string.Empty;
public string ControlSource { get; set; } = string.Empty;
public string TriggeredBy { get; set; } = string.Empty;
public DateTime TriggeredOn { get; set; }
public int? DurationMs { get; set; }
public bool Success { get; set; }
public string? ErrorMessage { get; set; }
}
// ── Snapshot list item (response) ─────────────────────────────────────────────
///
/// One snapshot row returned by GetSnapshots.
/// SQL Server: from sys.databases (COW snapshot, near-instant creation).
/// PostgreSQL: from pg_database (full-copy template clone, naming convention {RunDb}_snap_{label}).
///
public class TCMSTestEnvSnapshotListDTO
{
public string SnapshotName { get; set; } = string.Empty;
public string SourceDatabase { get; set; } = string.Empty;
public DateTime CreateDate { get; set; }
public long SizeMb { get; set; }
}
// ── Sync / Deregister request DTOs ───────────────────────────────────────────
/// Payload for SyncFromControl — re-clone an existing run DB from its control source.
public class TCMSSyncFromControlDTO
{
public int ServerConfigId { get; set; }
public string TriggeredBy { get; set; } = string.Empty;
}
/// Payload for DeregisterTestDb.
public class TCMSDeregisterTestDbDTO
{
public int ServerConfigId { get; set; }
///
/// When true, BLL will DROP the physical database on the run DB server
/// before setting MSERVERCONFIG.STATUS=0.
///
public bool DropPhysicalDb { get; set; }
}
// ── Snapshot request DTOs ─────────────────────────────────────────────────────
/// Request to create a snapshot checkpoint of a run DB.
public class TCMSCreateSnapshotDTO
{
public int ServerConfigId { get; set; }
///
/// User-provided label. Full snapshot DB name: {RunDb}_snap_{SnapshotLabel}.
/// Must be a valid database identifier (no spaces, no special characters).
///
public string SnapshotLabel { get; set; } = string.Empty;
}
/// Request to restore a run DB to a named snapshot.
public class TCMSRestoreToSnapshotDTO
{
public int ServerConfigId { get; set; }
public string SnapshotLabel { get; set; } = string.Empty;
}
/// Request to drop a snapshot (free disk space).
public class TCMSDeleteSnapshotDTO
{
public int ServerConfigId { get; set; }
public string SnapshotLabel { get; set; } = string.Empty;
}
// ── Dropdown ──────────────────────────────────────────────────────────────────
/// MSERVER select-list item for the Register form's server dropdown.
public class TCMSMServerSelectDTO
{
public int ServerId { get; set; }
public string ServerName { get; set; } = string.Empty;
public string ServerIP { get; set; } = string.Empty;
}