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

/// <summary>
/// Request to write a SET of device tags through the DCL in ONE batch round-trip,
/// optionally followed by a trigger-flag write. Composes the adapter's
/// <see cref="ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Protocol.IDataConnection.WriteBatchAsync"/>
/// (the batch) with a single <c>WriteAsync</c> (the trigger) so the script-facing
/// <c>Attributes.WriteBatchAndWaitAsync</c> helper replaces N sequential per-attribute
/// writes with one gateway call. The wait half is the EXISTING event-driven
/// <c>WaitForAttribute</c> waiter — it is NOT part of this DCL message; failures are
/// returned synchronously to the calling Instance Actor.
/// </summary>
/// <param name="CorrelationId">Per-write correlation id; echoed on the response.</param>
/// <param name="ConnectionName">The data connection that owns every tag in the batch (and the trigger).</param>
/// <param name="Values">Device tag path → value to write in the single batch round-trip.</param>
/// <param name="TriggerTagPath">Optional device tag path of a flag written AFTER the batch succeeds; null to skip.</param>
/// <param name="TriggerValue">Value to write to <paramref name="TriggerTagPath"/> (ignored when it is null/empty).</param>
/// <param name="Timestamp">When the request was issued (UTC).</param>
public record WriteTagBatchRequest(
    string CorrelationId,
    string ConnectionName,
    IReadOnlyDictionary<string, object?> Values,   // device tagPath -> value
    string? TriggerTagPath,                          // optional flag written AFTER the batch
    object? TriggerValue,
    DateTimeOffset Timestamp);

/// <summary>
/// Response for a <see cref="WriteTagBatchRequest"/>. <see cref="Success"/> is true only
/// when the whole batch AND the optional trigger committed; otherwise
/// <see cref="ErrorMessage"/> describes the first failing leg.
/// </summary>
/// <param name="CorrelationId">Echoes the request's correlation id.</param>
/// <param name="Success">True when the batch (and trigger, if any) all committed.</param>
/// <param name="ErrorMessage">Non-null on failure — the aggregated batch error, the trigger error, a timeout, or an adapter exception.</param>
/// <param name="Timestamp">When the response was produced (UTC).</param>
public record WriteTagBatchResponse(
    string CorrelationId,
    bool Success,
    string? ErrorMessage,
    DateTimeOffset Timestamp);
