namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions;
///
/// Health snapshot a driver returns to the Core. Drives the status dashboard,
/// ServiceLevel computation, and Bad-quality fan-out decisions.
///
/// Current driver-instance state.
/// Timestamp of the most recent successful equipment read; null if never.
/// Most recent error message; null when state is Healthy.
///
/// Optional driver-attributable counters/metrics surfaced for the driver-diagnostics
/// RPC (introduced for Modbus task #154). Drivers populate the dictionary with stable,
/// well-known keys (e.g. PublishRequestCount, NotificationsPerSecond);
/// Core treats it as opaque metadata. Defaulted to an empty read-only dictionary so
/// existing drivers and call-sites that don't construct this field stay back-compat.
///
public sealed record DriverHealth(
DriverState State,
DateTime? LastSuccessfulRead,
string? LastError,
IReadOnlyDictionary? Diagnostics = null)
{
/// Driver-attributable counters, empty when the driver doesn't surface any.
public IReadOnlyDictionary DiagnosticsOrEmpty
=> Diagnostics ?? EmptyDiagnostics;
private static readonly IReadOnlyDictionary EmptyDiagnostics
= new Dictionary(0);
}
/// Driver-instance lifecycle state.
public enum DriverState
{
/// Driver has not been initialized yet.
Unknown,
/// Driver is in the middle of or .
Initializing,
/// Driver is connected and serving data.
Healthy,
/// Driver is connected but reporting degraded data (e.g. some equipment unreachable, some tags Bad).
Degraded,
/// Driver lost connection to its data source; reconnecting in the background.
Reconnecting,
///
/// Driver hit an unrecoverable error and stopped trying.
/// Operator must reinitialize via Admin UI; nodes report Bad quality.
///
Faulted,
}