using ZB.MOM.WW.OtOpcUa.Commons.Types;

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

public enum RedundancyRole { Primary, Secondary, Detached }

/// <summary>
/// Snapshot of a single node's redundancy state. Aggregated by <c>RedundancyStateActor</c>
/// to compute fleet-wide ServiceLevel.
/// </summary>
/// <param name="NodeId">Canonical <c>host:port</c> id of the node this entry describes.</param>
/// <param name="Role">The node's redundancy role in the current snapshot.</param>
/// <param name="IsClusterLeader">Whether the node is the Akka cluster leader.</param>
/// <param name="IsDriverPrimary">
/// Whether the node is the driver Primary — the <b>oldest</b> Up member carrying the <c>driver</c>
/// role, which is where <c>ClusterSingletonManager</c> places singletons. Renamed from
/// <c>IsRoleLeaderForDriver</c>: it was derived from <c>ClusterState.RoleLeader("driver")</c>, the
/// lowest-<i>addressed</i> member, which diverges from the oldest after any node restart. The name
/// now describes what the value means rather than how it used to be computed.
/// </param>
/// <param name="AsOfUtc">When the snapshot was computed.</param>
public sealed record NodeRedundancyState(
    NodeId NodeId,
    RedundancyRole Role,
    bool IsClusterLeader,
    bool IsDriverPrimary,
    DateTime AsOfUtc);
