namespace Mbproxy.Proxy.Multiplexing;

/// <summary>
/// Source-generated <see cref="LoggerMessage"/> definitions for the backend keepalive
/// heartbeat. Event names are stable — do not rename without updating
/// docs/Reference/LogEvents.md's event-name table.
/// </summary>
internal static partial class KeepaliveLogEvents
{
    /// <summary>
    /// Emitted each time the heartbeat loop issues a synthetic FC03 probe on an idle
    /// backend socket. Debug level — one per <c>BackendHeartbeatIdleMs</c> per idle PLC.
    /// </summary>
    [LoggerMessage(
        EventId   = 150,
        EventName = "mbproxy.keepalive.heartbeat.sent",
        Level     = LogLevel.Debug,
        Message   = "Keepalive heartbeat sent: Plc={Plc} ProxyTxId={ProxyTxId} Address={Address}")]
    public static partial void HeartbeatSent(
        ILogger logger,
        string  plc,
        ushort  proxyTxId,
        ushort  address);

    /// <summary>
    /// Emitted when a keepalive heartbeat probe is not answered within
    /// <c>BackendRequestTimeoutMs</c>. The backend is connected-but-not-answering; the
    /// multiplexer tears it down (see <see cref="BackendIdleDisconnect"/>).
    /// </summary>
    [LoggerMessage(
        EventId   = 151,
        EventName = "mbproxy.keepalive.heartbeat.timeout",
        Level     = LogLevel.Warning,
        Message   = "Keepalive heartbeat timed out: Plc={Plc} ProxyTxId={ProxyTxId} ElapsedMs={ElapsedMs}")]
    public static partial void HeartbeatTimeout(
        ILogger logger,
        string  plc,
        ushort  proxyTxId,
        long    elapsedMs);

    /// <summary>
    /// Emitted when a failed keepalive heartbeat triggers a proactive backend teardown.
    /// Every attached upstream pipe is cascaded; clients reconnect on their next request.
    /// </summary>
    [LoggerMessage(
        EventId   = 152,
        EventName = "mbproxy.keepalive.backend.idle_disconnect",
        Level     = LogLevel.Information,
        Message   = "Backend torn down by keepalive: Plc={Plc} HeartbeatElapsedMs={ElapsedMs}")]
    public static partial void BackendIdleDisconnect(
        ILogger logger,
        string  plc,
        long    elapsedMs);
}
