using ScadaLink.Commons.Entities.Audit;
using ScadaLink.Commons.Types;
using ScadaLink.Commons.Types.Audit;
namespace ScadaLink.Commons.Interfaces.Repositories;
///
/// Operational-state data access for the central SiteCalls table
/// (Site Call Audit #22, Audit Log #23 M3 Bundle B). One row per
/// ; sites remain the source of truth and this
/// table is an eventually-consistent mirror fed by best-effort gRPC telemetry
/// plus periodic reconciliation pulls.
///
///
///
/// Unlike the partitioned append-only AuditLog (M1), this table holds
/// mutable operational state. is insert-if-not-exists
/// then monotonic update — a status update with rank less than or equal to the
/// stored status is a silent no-op so out-of-order telemetry, duplicate gRPC
/// packets, and reconciliation pulls can all feed the same writer without
/// rolling state backward.
///
///
/// Status rank for monotonic comparison (lower wins): Submitted=0,
/// Forwarded=1, Attempted=2, Skipped=2, Delivered=3, Failed=3, Parked=3,
/// Discarded=3. Terminal statuses share rank 3 and are mutually exclusive
/// — an attempt to upsert e.g. Delivered over an existing Parked
/// row is a no-op.
///
///
public interface ISiteCallAuditRepository
{
///
/// Inserts if no row with the same
/// exists; otherwise updates the
/// existing row IF AND ONLY IF the incoming status' rank strictly exceeds
/// the stored status' rank. Out-of-order / duplicate updates are silently
/// dropped (monotonic forward-only progression).
///
Task UpsertAsync(SiteCall siteCall, CancellationToken ct = default);
///
/// Returns the row for the given id, or null if none exists.
///
Task GetAsync(TrackedOperationId id, CancellationToken ct = default);
///
/// Returns up to rows matching
/// , ordered by (CreatedAtUtc DESC,
/// TrackedOperationId DESC). Use keyset paging via
/// +
/// to fetch subsequent pages.
///
Task> QueryAsync(
SiteCallQueryFilter filter,
SiteCallPaging paging,
CancellationToken ct = default);
///
/// Deletes terminal rows whose is
/// strictly older than . Non-terminal rows
/// (TerminalAtUtc IS NULL) are NEVER purged. Returns the number of rows
/// deleted.
///
Task PurgeTerminalAsync(DateTime olderThanUtc, CancellationToken ct = default);
}