using MessagePack;

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

/// <summary>
///     First frame of every connection. Advertises protocol major/minor and the peer's feature set.
///     Major mismatch is fatal; minor is advisory. Per Task A.3.
/// </summary>
[MessagePackObject]
public sealed class Hello
{
    public const int CurrentMajor = 1;
    public const int CurrentMinor = 0;

    [Key(0)] public int ProtocolMajor { get; set; } = CurrentMajor;
    [Key(1)] public int ProtocolMinor { get; set; } = CurrentMinor;
    [Key(2)] public string PeerName { get; set; } = string.Empty;

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

    [Key(4)] public string[] Features { get; set; } = System.Array.Empty<string>();
}

[MessagePackObject]
public sealed class HelloAck
{
    [Key(0)] public int ProtocolMajor { get; set; } = Hello.CurrentMajor;
    [Key(1)] public int ProtocolMinor { get; set; } = Hello.CurrentMinor;

    /// <summary>True if the server accepted the hello; false + <see cref="RejectReason"/> filled if not.</summary>
    [Key(2)] public bool Accepted { get; set; }
    [Key(3)] public string? RejectReason { get; set; }

    [Key(4)] public string HostName { get; set; } = string.Empty;
}
