using ZB.MOM.WW.MxGateway.Contracts.Proto;

namespace ZB.MOM.WW.MxGateway.Client;

/// <summary>
/// Exception thrown when the gateway returns a protocol-OK reply that carries neither the
/// expected typed payload nor an int32 <c>return_value</c>, so the client cannot resolve the
/// operation result. This replaces the historical <see cref="NullReferenceException"/> that a
/// blind <c>reply.ReturnValue.Int32Value</c> fallback would throw.
/// </summary>
public sealed class MxGatewayMalformedReplyException : MxGatewayException
{
    /// <summary>Initializes a new instance with the given message.</summary>
    /// <param name="message">The error message describing the malformed reply.</param>
    public MxGatewayMalformedReplyException(string message)
        : base(message)
    {
    }

    /// <summary>Initializes a new instance with full diagnostic context.</summary>
    /// <param name="message">The error message describing the malformed reply.</param>
    /// <param name="sessionId">The session ID, if available.</param>
    /// <param name="correlationId">The correlation ID for tracing, if available.</param>
    /// <param name="protocolStatus">The protocol status details, if available.</param>
    /// <param name="hResult">The HResult code, if available.</param>
    /// <param name="statuses">The MXAccess statuses, if available.</param>
    /// <param name="innerException">The underlying exception, if any.</param>
    public MxGatewayMalformedReplyException(
        string message,
        string? sessionId = null,
        string? correlationId = null,
        ProtocolStatus? protocolStatus = null,
        int? hResult = null,
        IReadOnlyList<MxStatusProxy>? statuses = null,
        Exception? innerException = null)
        : base(
            message,
            sessionId,
            correlationId,
            protocolStatus,
            hResult,
            statuses ?? [],
            innerException)
    {
    }
}
