namespace ZB.MOM.WW.OtOpcUa.Configuration.Entities;

/// <summary>
///     Runtime resilience counters the CapabilityInvoker + MemoryTracking + MemoryRecycle
///     surfaces for each <c>(DriverInstanceId, HostName)</c> pair. Separate from
///     <see cref="DriverHostStatus"/> (which owns per-host <i>connectivity</i> state) so a
///     host that's Running but has tripped its breaker or is approaching its memory ceiling
///     shows up distinctly on Admin <c>/hosts</c>.
/// </summary>
/// <remarks>
///     Per <c>docs/v2/implementation/phase-6-1-resilience-and-observability.md</c> §Stream E.1.
///     The Admin UI left-joins this table on DriverHostStatus for display; rows are written
///     by the runtime via a HostedService that samples the tracker at a configurable
///     interval (default 5 s) — writes are non-critical, a missed sample is tolerated.
/// </remarks>
public sealed class DriverInstanceResilienceStatus
{
    /// <summary>Gets or sets the driver instance identifier.</summary>
    public required string DriverInstanceId { get; set; }
    /// <summary>Gets or sets the host name.</summary>
    public required string HostName { get; set; }

    /// <summary>Most recent time the circuit breaker for this (instance, host) opened; null if never.</summary>
    public DateTime? LastCircuitBreakerOpenUtc { get; set; }

    /// <summary>Rolling count of consecutive Polly pipeline failures for this (instance, host).</summary>
    public int ConsecutiveFailures { get; set; }

    /// <summary>In-flight capability-call depth for this (instance, host). Formerly fed a Polly
    /// concurrency-limiter strategy that was removed (R2-02/01/U-6); the column name is retained to avoid a
    /// migration on a reader-less entity — it now carries the tracker's in-flight-call count.</summary>
    public int CurrentBulkheadDepth { get; set; }

    /// <summary>Most recent process recycle time (Tier C only; null for in-process tiers).</summary>
    public DateTime? LastRecycleUtc { get; set; }

    /// <summary>
    ///     Post-init memory baseline captured by <c>MemoryTracking</c> (median of first
    ///     BaselineWindow samples). Zero while still warming up.
    /// </summary>
    public long BaselineFootprintBytes { get; set; }

    /// <summary>Most recent footprint sample the tracker saw (steady-state read).</summary>
    public long CurrentFootprintBytes { get; set; }

    /// <summary>Row last-write timestamp — advances on every sampling tick.</summary>
    public DateTime LastSampledUtc { get; set; }
}
