namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Shared.Contracts;

/// <summary>
///     Length-prefixed framing. Each IPC frame is:
///     <c>[4-byte big-endian length][1-byte message kind][MessagePack body]</c>.
///     Length is the body size only; the kind byte is not part of the prefixed length.
///     Mirrors the Galaxy Tier-C framing so operators see one wire format across hosts.
/// </summary>
public static class Framing
{
    public const int LengthPrefixSize = 4;
    public const int KindByteSize = 1;

    /// <summary>
    ///     Maximum permitted body length (16 MiB). Protects the receiver from a hostile or
    ///     misbehaving peer sending an oversized length prefix.
    /// </summary>
    public const int MaxFrameBodyBytes = 16 * 1024 * 1024;
}

/// <summary>
///     Wire identifier for each contract. Values are stable — new contracts append, never
///     reuse. Ranges kept aligned with Galaxy so an operator reading a hex dump doesn't have
///     to context-switch between drivers.
/// </summary>
public enum FocasMessageKind : byte
{
    Hello                    = 0x01,
    HelloAck                 = 0x02,
    Heartbeat                = 0x03,
    HeartbeatAck             = 0x04,

    OpenSessionRequest       = 0x10,
    OpenSessionResponse      = 0x11,
    CloseSessionRequest      = 0x12,

    ReadRequest              = 0x30,
    ReadResponse             = 0x31,
    WriteRequest             = 0x32,
    WriteResponse            = 0x33,
    PmcBitWriteRequest       = 0x34,
    PmcBitWriteResponse      = 0x35,

    SubscribeRequest         = 0x40,
    SubscribeResponse        = 0x41,
    UnsubscribeRequest       = 0x42,
    OnDataChangeNotification = 0x43,

    ProbeRequest             = 0x70,
    ProbeResponse            = 0x71,
    RuntimeStatusChange      = 0x72,

    RecycleHostRequest       = 0xF0,
    RecycleStatusResponse    = 0xF1,

    ErrorResponse            = 0xFE,
}
