using ZB.MOM.WW.Audit;
using ZB.MOM.WW.ScadaBridge.Commons.Types;

namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Integration;

/// <summary>
/// Combined audit + operational telemetry packet for cached outbound calls.
/// The site emits one packet per lifecycle event
/// — <c>Submit</c> (Audit kind <c>CachedSubmit</c>), per-attempt
/// <c>ApiCallCached</c>/<c>DbWriteCached</c>, terminal <c>CachedResolve</c> —
/// and central writes the <see cref="AuditEvent"/> row plus the
/// <see cref="SiteCallOperational"/> upsert in one MS SQL transaction. Two
/// payload shapes ride on a single wire message so the same on-the-wire batch
/// can carry mixed lifecycle events without the central dual-write needing a
/// second RPC for the operational state.
/// </summary>
/// <remarks>
/// <para>
/// Both inner records carry the same <c>TrackedOperationId</c> — the
/// idempotency key end-to-end. The <see cref="AuditEvent.CorrelationId"/>
/// pattern (used by Audit Log to thread cached-call rows together) is
/// honoured by the site emitter; the packet itself is shape-only and makes no
/// independent correlation guarantees.
/// </para>
/// <para>
/// Additive-only per Commons REQ-COM-5a — this is a new
/// message, not a rename of any existing envelope.
/// </para>
/// </remarks>
/// <param name="Audit">The Audit Log row to insert at central.</param>
/// <param name="Operational">The <c>SiteCalls</c> upsert mirroring this lifecycle event.</param>
public sealed record CachedCallTelemetry(
    AuditEvent Audit,
    SiteCallOperational Operational);
