/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { InternalError } from "#general";
import { BdxMessageType } from "#types";
import { BdxReceiveAcceptMessage, BdxSendAcceptMessage } from "./BdxAcceptMessagesSchema.js";
import {
  BdxBlockAckEofMessage,
  BdxBlockAckMessage,
  BdxBlockEofMessage,
  BdxBlockMessage,
  BdxBlockQueryMessage,
  BdxBlockQueryWithSkipMessage
} from "./BdxBlockMessagesSchema.js";
import { BdxReceiveInitMessage, BdxSendInitMessage } from "./BdxInitMessagesSchema.js";
var BdxMessage;
((BdxMessage2) => {
  function encode({ kind, message }) {
    if (!(kind in BdxMessage2.Kinds)) {
      throw new InternalError(`Can not encode unknown BDX message type: ${kind}`);
    }
    return BdxMessage2.Kinds[kind].encode(message);
  }
  BdxMessage2.encode = encode;
  function decode(kind, payload) {
    if (!(kind in BdxMessage2.Kinds)) {
      throw new InternalError(`Can not decode unknown BDX message type: ${kind}`);
    }
    return { kind, message: BdxMessage2.Kinds[kind].decode(payload) };
  }
  BdxMessage2.decode = decode;
  function is(message, kind) {
    return message.kind === kind;
  }
  BdxMessage2.is = is;
  function assert(message, kind) {
    if (message.kind !== kind) {
      throw new InternalError(
        `Expected BDX message of type ${BdxMessageType[kind]}, but got ${BdxMessageType[message.kind]}(${message.kind})`
      );
    }
  }
  BdxMessage2.assert = assert;
  BdxMessage2.Kinds = {
    [BdxMessageType.SendInit]: BdxSendInitMessage,
    [BdxMessageType.ReceiveInit]: BdxReceiveInitMessage,
    [BdxMessageType.SendAccept]: BdxSendAcceptMessage,
    [BdxMessageType.ReceiveAccept]: BdxReceiveAcceptMessage,
    [BdxMessageType.BlockQuery]: BdxBlockQueryMessage,
    [BdxMessageType.BlockQueryWithSkip]: BdxBlockQueryWithSkipMessage,
    [BdxMessageType.Block]: BdxBlockMessage,
    [BdxMessageType.BlockEof]: BdxBlockEofMessage,
    [BdxMessageType.BlockAck]: BdxBlockAckMessage,
    [BdxMessageType.BlockAckEof]: BdxBlockAckEofMessage
  };
})(BdxMessage || (BdxMessage = {}));
export {
  BdxMessage
};
//# sourceMappingURL=BdxMessage.js.map
