namespace Mbproxy.Proxy;

/// <summary>
/// Source-generated <see cref="LoggerMessage"/> definitions for the BCD rewriter pipeline.
/// All event names are stable — do not rename without updating docs/Reference/LogEvents.md.
/// </summary>
internal static partial class RewriterLogEvents
{
    /// <summary>
    /// Emitted when a 32-bit BCD pair is only partially covered by the read/write range.
    /// The raw bytes are passed through unchanged; the client or PLC sees the original nibbles.
    /// </summary>
    [LoggerMessage(
        EventId   = 30,
        EventName = "mbproxy.rewrite.partial_bcd",
        Level     = LogLevel.Warning,
        Message   = "Partial BCD overlap — passing through raw: Plc={PlcName} Address={Address} ClientStart={ClientStart} ClientQty={ClientQty}")]
    public static partial void PartialBcd(
        ILogger logger,
        string  plcName,
        ushort  address,
        ushort  clientStart,
        ushort  clientQty);

    /// <summary>
    /// Emitted when a register value at a configured BCD address contains a nibble >= 0xA
    /// (i.e. not a valid BCD digit). The raw bytes are passed through unchanged.
    /// Direction is "Read" (response from PLC) or "Write" (request from client).
    /// </summary>
    [LoggerMessage(
        EventId   = 31,
        EventName = "mbproxy.rewrite.invalid_bcd",
        Level     = LogLevel.Warning,
        Message   = "Invalid BCD nibble — passing through raw: Plc={PlcName} Address={Address} RawValue=0x{RawValue:X4} Direction={Direction}")]
    public static partial void InvalidBcd(
        ILogger logger,
        string  plcName,
        ushort  address,
        ushort  rawValue,
        string  direction);

    /// <summary>
    /// Emitted when the PLC returns a Modbus exception response (high bit set on FC byte).
    /// The frame is forwarded verbatim to the client.
    /// </summary>
    [LoggerMessage(
        EventId   = 32,
        EventName = "mbproxy.exception.passthrough",
        Level     = LogLevel.Information,
        Message   = "Modbus exception forwarded: Plc={PlcName} Fc=0x{Fc:X2} ExceptionCode={ExceptionCode}")]
    public static partial void ExceptionPassthrough(
        ILogger logger,
        string  plcName,
        byte    fc,
        byte    exceptionCode);
}
