namespace NATS.Server.Raft;

/// <summary>
/// RAFT internal subject patterns using the $NRG.* prefix.
/// All RAFT RPC traffic within a cluster flows over these subjects,
/// scoped to a named RAFT group (the NRG — NATS Raft Group) identifier.
///
/// Go reference: golang/nats-server/server/raft.go:2161-2169
/// </summary>
public static class RaftSubjects
{
    /// <summary>
    /// Wildcard subject matching all RAFT traffic for any group.
    /// Go: server/raft.go:2162 — raftAllSubj = "$NRG.>"
    /// </summary>
    public const string All = "$NRG.>";

    /// <summary>
    /// Vote request subject for the given RAFT group.
    /// Go: server/raft.go:2163 — raftVoteSubj = "$NRG.V.%s"
    /// </summary>
    public static string Vote(string group) => $"$NRG.V.{group}";

    /// <summary>
    /// AppendEntry subject for the given RAFT group.
    /// Go: server/raft.go:2164 — raftAppendSubj = "$NRG.AE.%s"
    /// </summary>
    public static string AppendEntry(string group) => $"$NRG.AE.{group}";

    /// <summary>
    /// Proposal (forward proposal) subject for the given RAFT group.
    /// Go: server/raft.go:2165 — raftPropSubj = "$NRG.P.%s"
    /// </summary>
    public static string Proposal(string group) => $"$NRG.P.{group}";

    /// <summary>
    /// Remove-peer proposal subject for the given RAFT group.
    /// Go: server/raft.go:2166 — raftRemovePeerSubj = "$NRG.RP.%s"
    /// </summary>
    public static string RemovePeer(string group) => $"$NRG.RP.{group}";

    /// <summary>
    /// Reply inbox subject for a one-shot RPC reply.
    /// Go: server/raft.go:2167 — raftReply = "$NRG.R.%s"
    /// </summary>
    public static string Reply(string id) => $"$NRG.R.{id}";

    /// <summary>
    /// Catchup reply subject used during log catch-up streaming.
    /// Go: server/raft.go:2168 — raftCatchupReply = "$NRG.CR.%s"
    /// </summary>
    public static string CatchupReply(string id) => $"$NRG.CR.{id}";

    /// <summary>
    /// TimeoutNow subject for the given RAFT group.
    /// Sent by a leader to a target follower to trigger immediate election
    /// for leadership transfer. Mirrors Go's sendTimeoutNow pattern.
    /// Go reference: raft.go sendTimeoutNow
    /// </summary>
    public static string TimeoutNow(string group) => $"$NRG.TN.{group}";
}
