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

/// <summary>
///     Tunables for <see cref="FailoverAlarmConsumer"/>'s auto-failover /
///     auto-failback state machine. Constructor-clamped to safe minimums so a
///     misconfigured options bind can never produce a zero/negative threshold
///     that would either never fail over or fail over on the first hiccup
///     unintentionally.
/// </summary>
/// <remarks>
///     <para>
///         Plain class with constructor-assigned get-only properties — not a
///         <c>record</c> or <c>init</c>-only type — because the worker
///         multi-targets .NET Framework 4.8, which lacks
///         <c>System.Runtime.CompilerServices.IsExternalInit</c> and so cannot
///         compile <c>init</c> accessors or positional records (CS0518).
///     </para>
/// </remarks>
public sealed class FailoverSettings
{
    /// <summary>
    ///     Initializes the settings, clamping each value to its safe minimum.
    /// </summary>
    /// <param name="threshold">
    ///     Consecutive primary COM failures that trigger a switch to standby.
    ///     Clamped to a minimum of 1.
    /// </param>
    /// <param name="probeIntervalSeconds">
    ///     Minimum spacing (seconds) between failback probes against the
    ///     recovering primary. Clamped to a minimum of 0 (probe every tick).
    /// </param>
    /// <param name="stableProbes">
    ///     Consecutive clean failback probes required before switching back to
    ///     the primary. Clamped to a minimum of 1.
    /// </param>
    public FailoverSettings(int threshold, int probeIntervalSeconds, int stableProbes)
    {
        Threshold = threshold < 1 ? 1 : threshold;
        ProbeIntervalSeconds = probeIntervalSeconds < 0 ? 0 : probeIntervalSeconds;
        StableProbes = stableProbes < 1 ? 1 : stableProbes;
    }

    /// <summary>
    ///     Consecutive primary COM failures that trigger a switch to standby.
    /// </summary>
    public int Threshold { get; }

    /// <summary>
    ///     Minimum spacing, in seconds, between failback probes.
    /// </summary>
    public int ProbeIntervalSeconds { get; }

    /// <summary>
    ///     Consecutive clean failback probes required before failing back.
    /// </summary>
    public int StableProbes { get; }
}
