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

/// <summary>
///     Thread-safe <c>UsingStaleConfig</c> signal per Phase 6.1 Stream D.3. Flips true whenever
///     a read falls back to a sealed cache snapshot; flips false on the next successful central-DB
///     round-trip. Surfaced on <c>/healthz</c> body and on the Admin <c>/hosts</c> page.
/// </summary>
public sealed class StaleConfigFlag
{
    private int _stale;

    /// <summary>True when the last config read was served from the sealed cache, not the central DB.</summary>
    public bool IsStale => Volatile.Read(ref _stale) != 0;

    /// <summary>Mark the current config as stale (a read fell back to the cache).</summary>
    public void MarkStale() => Volatile.Write(ref _stale, 1);

    /// <summary>Mark the current config as fresh (a central-DB read succeeded).</summary>
    public void MarkFresh() => Volatile.Write(ref _stale, 0);
}
