// src/engine/remoting/IRequestReplyEnvelope.ts
//
// Simplified Request/Reply Envelope for Internal RPC
//
// This is a MINIMAL envelope used for intra-root request/reply patterns.
// For cross-root federation, use MxEnvelopeV1 from packages/matrix-transport.
//
// See RequestReplyHelper.ts for the full envelope hierarchy documentation.

/**
 * Request/Reply envelope - wraps RPC-style requests (internal use).
 *
 * This is a simplified envelope for intra-root RPC. For cross-root
 * federation, see MxEnvelopeV1 in packages/matrix-transport which
 * includes full routing, security, and tracing fields.
 */
export interface IRequestReplyEnvelope<TParams = unknown> {
  /** Correlation ID for matching request/response */
  correlationId: string;
  /** Topic path for publishing the reply */
  replyTo: string;
  /** Request parameters (payload) */
  params?: TParams;
}

/**
 * Type guard: Check if payload is a Request/Reply envelope.
 *
 * Detects both IRequestReplyEnvelope (internal) and the params extracted
 * from MxEnvelopeV1 (cross-root) by FederationPeer.
 */
export function isRequestReplyEnvelope(payload: unknown): payload is IRequestReplyEnvelope {
  return (
    payload !== null &&
    typeof payload === 'object' &&
    'correlationId' in payload &&
    'replyTo' in payload
  );
}
