using System;

namespace ZB.MOM.WW.MxGateway.Worker.MxAccess;

public sealed class WorkerRuntimeHeartbeatSnapshot
{
    /// <summary>Initializes a new instance of the <see cref="WorkerRuntimeHeartbeatSnapshot"/> class.</summary>
    /// <param name="lastStaActivityUtc">Timestamp of the last STA thread activity in UTC.</param>
    /// <param name="pendingCommandCount">Number of commands awaiting processing.</param>
    /// <param name="outboundEventQueueDepth">Current depth of the worker event queue.</param>
    /// <param name="lastEventSequence">Sequence number of the most recent event.</param>
    /// <param name="currentCommandCorrelationId">Correlation ID of the in-flight command.</param>
    /// <param name="staCallInProgress">
    /// True while an STA call outside the command dispatcher is executing (currently the alarm poll,
    /// WRK-27). The watchdog treats this like an in-flight command: it suppresses the stale-STA fault
    /// up to the stuck ceiling instead of the shorter grace, so a healthy-but-slow poll does not fault
    /// a healthy session. Named generically so any future non-dispatcher STA work reuses it.
    /// </param>
    public WorkerRuntimeHeartbeatSnapshot(
        DateTimeOffset lastStaActivityUtc,
        uint pendingCommandCount,
        uint outboundEventQueueDepth,
        ulong lastEventSequence,
        string currentCommandCorrelationId,
        bool staCallInProgress = false)
    {
        LastStaActivityUtc = lastStaActivityUtc;
        PendingCommandCount = pendingCommandCount;
        OutboundEventQueueDepth = outboundEventQueueDepth;
        LastEventSequence = lastEventSequence;
        CurrentCommandCorrelationId = currentCommandCorrelationId ?? string.Empty;
        StaCallInProgress = staCallInProgress;
    }

    /// <summary>Gets the last STA activity timestamp in UTC.</summary>
    public DateTimeOffset LastStaActivityUtc { get; }

    /// <summary>Gets the pending command count.</summary>
    public uint PendingCommandCount { get; }

    /// <summary>Gets the current depth of the worker event queue.</summary>
    public uint OutboundEventQueueDepth { get; }

    /// <summary>Gets the sequence number of the most recent event.</summary>
    public ulong LastEventSequence { get; }

    /// <summary>Gets the correlation ID of the in-flight command.</summary>
    public string CurrentCommandCorrelationId { get; }

    /// <summary>
    /// Gets a value indicating whether an STA call outside the command dispatcher (the alarm poll) is
    /// executing. When true the watchdog grants the poll the same grace-to-ceiling suppression as a
    /// dispatched command (WRK-27).
    /// </summary>
    public bool StaCallInProgress { get; }
}
