namespace ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;

/// <summary>
///     Snapshot of a single driver instance's health, published to the
///     <c>driver-health</c> DistributedPubSub topic whenever a driver actor
///     transitions state or logs an error. Consumed by
///     <c>DriverStatusSignalRBridge</c> in the AdminUI for live status push.
/// </summary>
/// <param name="ClusterId">Cluster this driver belongs to.</param>
/// <param name="DriverInstanceId">Globally-unique driver instance ID.</param>
/// <param name="State">DriverState enum as string (Healthy, Faulted, Reconnecting, etc.).</param>
/// <param name="LastSuccessfulReadUtc">Most recent successful equipment read; null if never.</param>
/// <param name="LastError">Latest error message; null when none.</param>
/// <param name="ErrorCount5Min">Number of state-transitions into Faulted in the last 5 minutes.</param>
/// <param name="PublishedUtc">Timestamp this snapshot was published.</param>
/// <param name="RediscoveryNeededUtc">
///     When the driver last raised <c>IRediscoverable.OnRediscoveryNeeded</c> — i.e. it observed that the
///     remote's tag set may have changed (a Galaxy redeploy, a TwinCAT symbol-version bump, an MTConnect
///     agent restart, a Sparkplug rebirth). Null when the driver has never raised it, or does not
///     implement <c>IRediscoverable</c>.
///     <para><b>Advisory only.</b> The served address space is NOT rebuilt in response — raw tags are
///     authored explicitly through the <c>/raw</c> browse-commit flow. This is a prompt for an operator
///     to re-browse the device and commit whatever changed.</para>
/// </param>
/// <param name="RediscoveryReason">
///     The driver-supplied reason string from the same event (e.g. <c>"deploy-time-changed"</c>), shown
///     to the operator alongside the prompt. Null when <paramref name="RediscoveryNeededUtc"/> is null.
/// </param>
public sealed record DriverHealthChanged(
    string ClusterId,
    string DriverInstanceId,
    string State,
    DateTime? LastSuccessfulReadUtc,
    string? LastError,
    int ErrorCount5Min,
    DateTime PublishedUtc,
    DateTime? RediscoveryNeededUtc = null,
    string? RediscoveryReason = null)
{
    /// <summary>
    ///     DPS topic name. Both the runtime <c>AkkaDriverHealthPublisher</c> and the AdminUI
    ///     <c>DriverStatusSignalRBridge</c> reference this single constant so renames can't
    ///     silently desynchronise publisher and subscriber.
    /// </summary>
    public const string TopicName = "driver-health";
}
