namespace Mbproxy.Proxy.Multiplexing;

/// <summary>
/// Hash key for the in-flight-by-key map. Two FC03/FC04 requests with identical
/// <see cref="UnitId"/>, <see cref="Fc"/>, <see cref="StartAddress"/>, and <see cref="Qty"/>
/// can be coalesced onto a single backend round-trip — the second request's response is
/// fanned out from the first request's reply, with each upstream party's original MBAP
/// transaction ID restored individually.
///
/// <para><b>Equality semantics:</b> auto-generated record-struct value equality. FC03 and
/// FC04 produce different keys for the same address (different Modbus tables); different
/// <see cref="UnitId"/> bytes never coalesce (different PLC personalities behind a shared
/// socket); reads of different <see cref="Qty"/> never coalesce (the responses carry
/// different register counts and would not be interchangeable on a fan-out).</para>
///
/// <para><b>Scope:</b> only FC03 (Read Holding Registers) and FC04 (Read Input Registers)
/// are coalescable. FC06 (Write Single Register), FC16 (Write Multiple Registers), and
/// any non-read function code bypass coalescing entirely — writes are non-idempotent and
/// must hit the backend each time.</para>
/// </summary>
internal readonly record struct CoalescingKey(
    byte UnitId,
    byte Fc,
    ushort StartAddress,
    ushort Qty);
