using ZB.MOM.WW.ScadaBridge.Commons.Entities.SecuredWrites;
namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
///
/// Operational-state data access for the central PendingSecuredWrites table.
/// One row per pending two-person secured
/// write; rows are inserted at submission and mutated as the request is decided and
/// executed. Mirrors the SiteCalls repository shape.
///
public interface ISecuredWriteRepository
{
///
/// Inserts and returns the store-generated
/// .
///
/// The pending secured write to persist.
/// Cancellation token.
/// A task that resolves to the generated identity of the inserted row.
Task AddAsync(PendingSecuredWrite securedWrite, CancellationToken ct = default);
///
/// Returns the row for the given id, or null if none exists.
///
/// The identity to look up.
/// Cancellation token.
/// A task that resolves to the matching , or null if no row exists.
Task GetAsync(long id, CancellationToken ct = default);
///
/// Persists the current state of (matched by
/// ).
///
/// The tracked entity whose changes to persist.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task UpdateAsync(PendingSecuredWrite securedWrite, CancellationToken ct = default);
///
/// Returns up to rows (skipping )
/// optionally filtered by and ,
/// ordered by SubmittedAtUtc DESC, Id DESC. A null filter argument
/// matches every row.
///
/// Status filter; null matches every status.
/// Site id filter; null matches every site.
/// Number of rows to skip (offset paging).
/// Maximum number of rows to return.
/// Cancellation token.
/// A task that resolves to a page of matching rows, newest submission first.
Task> QueryAsync(
string? status,
string? siteId,
int skip,
int take,
CancellationToken ct = default);
///
/// Atomically flips a row from Pending to Approved, stamping the
/// verifier identity, comment, and decision time, but ONLY if the row is still
/// Pending. This is the compare-and-swap guard for the two-verifier race:
/// two verifiers may approve the same write concurrently, but the
/// conditional WHERE Status='Pending' guarantees exactly one wins. The
/// loser observes false and must not relay the write.
///
/// Identity of the pending secured write.
/// The approving verifier's username.
/// Optional free-text comment from the verifier.
/// UTC instant the approval decision was made.
/// Cancellation token.
///
/// A task resolving to true if this caller won the approval (exactly one
/// row transitioned), or false if the row was no longer Pending
/// (already decided by another verifier).
///
Task TryMarkApprovedAsync(
long id,
string verifierUser,
string? verifierComment,
DateTime decidedAtUtc,
CancellationToken ct = default);
}