namespace NATS.Server;

/// <summary>
/// Reason a client connection was closed.
/// Corresponds to Go server/client.go ClosedState (subset for single-server scope).
/// </summary>
public enum ClientClosedReason
{
    None = 0,
    ClientClosed,
    AuthenticationTimeout,
    AuthenticationViolation,
    TlsHandshakeError,
    SlowConsumerPendingBytes,
    SlowConsumerWriteDeadline,
    WriteError,
    ReadError,
    ParseError,
    StaleConnection,
    ProtocolViolation,
    MaxPayloadExceeded,
    MaxSubscriptionsExceeded,
    ServerShutdown,
    MsgHeaderViolation,
    NoRespondersRequiresHeaders,
    AuthenticationExpired,
}

public static class ClientClosedReasonExtensions
{
    public static string ToReasonString(this ClientClosedReason reason) => reason switch
    {
        ClientClosedReason.None => "",
        ClientClosedReason.ClientClosed => "Client Closed",
        ClientClosedReason.AuthenticationTimeout => "Authentication Timeout",
        ClientClosedReason.AuthenticationViolation => "Authorization Violation",
        ClientClosedReason.TlsHandshakeError => "TLS Handshake Error",
        ClientClosedReason.SlowConsumerPendingBytes => "Slow Consumer (Pending Bytes)",
        ClientClosedReason.SlowConsumerWriteDeadline => "Slow Consumer (Write Deadline)",
        ClientClosedReason.WriteError => "Write Error",
        ClientClosedReason.ReadError => "Read Error",
        ClientClosedReason.ParseError => "Parse Error",
        ClientClosedReason.StaleConnection => "Stale Connection",
        ClientClosedReason.ProtocolViolation => "Protocol Violation",
        ClientClosedReason.MaxPayloadExceeded => "Maximum Payload Exceeded",
        ClientClosedReason.MaxSubscriptionsExceeded => "Maximum Subscriptions Exceeded",
        ClientClosedReason.ServerShutdown => "Server Shutdown",
        ClientClosedReason.MsgHeaderViolation => "Message Header Violation",
        ClientClosedReason.NoRespondersRequiresHeaders => "No Responders Requires Headers",
        ClientClosedReason.AuthenticationExpired => "Authentication Expired",
        _ => reason.ToString(),
    };
}
