namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Wonderware.Ipc;

/// <summary>
///     Length-prefixed framing constants for the Wonderware historian sidecar pipe protocol.
///     Each frame on the wire 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.
/// </summary>
/// <remarks>
///     Mirrors the Galaxy.Shared framing exactly so the same FrameReader/FrameWriter pattern
///     works on both sides. The sidecar's protocol is independent — both the .NET 4.8 server
///     side and the .NET 10 client (PR 3.4) carry their own copies of these constants and
///     stay in sync via the round-trip test matrix.
/// </remarks>
public static class Framing
{
    public const int LengthPrefixSize = 4;
    public const int KindByteSize = 1;

    /// <summary>16 MiB cap protects the receiver from a hostile or buggy peer.</summary>
    public const int MaxFrameBodyBytes = 16 * 1024 * 1024;
}

/// <summary>
///     Wire identifier for each historian sidecar message. Values are stable — never reorder;
///     append new contracts at the end. The .NET 10 client and the .NET 4.8 sidecar must
///     agree on every value here.
/// </summary>
public enum MessageKind : byte
{
    Hello                       = 0x01,
    HelloAck                    = 0x02,

    ReadRawRequest              = 0x10,
    ReadRawReply                = 0x11,

    ReadProcessedRequest        = 0x12,
    ReadProcessedReply          = 0x13,

    ReadAtTimeRequest           = 0x14,
    ReadAtTimeReply             = 0x15,

    ReadEventsRequest           = 0x16,
    ReadEventsReply             = 0x17,

    WriteAlarmEventsRequest     = 0x20,
    WriteAlarmEventsReply       = 0x21,
}
