using MessagePack;

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

/// <summary>
///     First frame of every connection. Advertises the sidecar protocol version and the
///     per-process shared secret the supervisor passed at spawn time.
/// </summary>
[MessagePackObject]
public sealed class Hello
{
    public const int CurrentMajor = 1;
    public const int CurrentMinor = 0;

    /// <summary>Gets or sets the protocol major version.</summary>
    [Key(0)] public int ProtocolMajor { get; set; } = CurrentMajor;
    /// <summary>Gets or sets the protocol minor version.</summary>
    [Key(1)] public int ProtocolMinor { get; set; } = CurrentMinor;
    /// <summary>Gets or sets the peer name.</summary>
    [Key(2)] public string PeerName { get; set; } = string.Empty;

    /// <summary>Per-process shared secret — verified against the value the supervisor passed at spawn time.</summary>
    [Key(3)] public string SharedSecret { get; set; } = string.Empty;
}

/// <summary>Response to a Hello handshake message.</summary>
[MessagePackObject]
public sealed class HelloAck
{
    /// <summary>Gets or sets the protocol major version.</summary>
    [Key(0)] public int ProtocolMajor { get; set; } = Hello.CurrentMajor;
    /// <summary>Gets or sets the protocol minor version.</summary>
    [Key(1)] public int ProtocolMinor { get; set; } = Hello.CurrentMinor;

    /// <summary>Gets or sets a value indicating whether the handshake was accepted.</summary>
    [Key(2)] public bool Accepted { get; set; }
    /// <summary>Gets or sets the rejection reason if Accepted is false.</summary>
    [Key(3)] public string? RejectReason { get; set; }
    /// <summary>Gets or sets the host name of the server.</summary>
    [Key(4)] public string HostName { get; set; } = string.Empty;
}
