namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
// ============================================================================
// Two-person ("secured") write commands.
//
// An Operator SUBMITS a pending secured write against an MxGateway data
// connection; a distinct Verifier later APPROVES (executes) or
// REJECTS it. Separation of duties is enforced at the handler: a write may not
// be verified by the same principal that submitted it. ListSecuredWrites is a
// read-only query (any authenticated user). Role gating lives in
// ManagementActor.GetRequiredRole (Operator for submit; Verifier for
// reject/approve).
// ============================================================================
///
/// Operator request to submit a pending secured write. The target connection
/// must exist within the site and use the MxGateway protocol; the value is
/// captured as interpreted per .
/// Returns the newly-created .
///
/// Site identifier the write targets.
/// Data connection name within the site.
/// Fully-qualified tag path the value is written to.
/// JSON-serialised value to write.
/// Target data type name (e.g. Boolean, Double).
/// Optional free-text comment supplied by the operator.
public record SubmitSecuredWriteCommand(
string SiteId,
string ConnectionName,
string TagPath,
string ValueJson,
string ValueType,
string? Comment);
///
/// Verifier request to approve (and execute) a pending
/// secured write. Declared here so the secured-write contract is complete; the
/// approve→execute relay handler and dispatch arm are implemented separately.
///
/// Identity of the pending secured write.
/// Optional free-text comment supplied by the verifier.
public record ApproveSecuredWriteCommand(long Id, string? Comment);
///
/// Verifier request to reject a pending secured write. The write must still be
/// Pending, and the verifier must differ from the submitting operator
/// (separation of duties). Returns the updated .
///
/// Identity of the pending secured write.
/// Optional free-text comment supplied by the verifier.
public record RejectSecuredWriteCommand(long Id, string? Comment);
///
/// Read-only query for secured writes, optionally filtered by status and site,
/// with offset paging. A null filter matches every row. The
/// / defaults preserve the historical unpaged wire behaviour
/// (first 200 rows) for callers that omit them (additive evolution).
///
/// Status filter; null matches every status.
/// Site id filter; null matches every site.
/// Number of rows to skip (offset paging); clamped to >= 0 server-side.
/// Maximum rows to return; clamped to 1..500 server-side. Default 200.
public record ListSecuredWritesCommand(string? Status, string? SiteId, int Skip = 0, int Take = 200);
///
/// Result projection of a single pending secured write row, mirroring the
/// PendingSecuredWrite entity shape.
///
public record SecuredWriteDto(
long Id,
string SiteId,
string ConnectionName,
string TagPath,
string ValueJson,
string ValueType,
string Status,
string OperatorUser,
string? OperatorComment,
DateTime SubmittedAtUtc,
string? VerifierUser,
string? VerifierComment,
DateTime? DecidedAtUtc,
DateTime? ExecutedAtUtc,
string? ExecutionError);
///
/// Result wrapper for .
/// is the count of rows matching the query filters ignoring paging, so the UI can render
/// a pager independent of the returned page size.
///
/// The page of matching secured-write rows.
/// Total number of rows matching the filters (unpaged).
public record SecuredWriteListResult(IReadOnlyList Items, int TotalCount);