/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { DataReader, DataWriter, Endian } from "#general";
import { Schema, VendorId } from "#types";
class ProtocolStatusMessageSchema extends Schema {
  #protocolId;
  #vendorId;
  #protocolSpecificDataAllowed;
  constructor(protocol, protocolSpecificDataAllowed = true) {
    super();
    if (typeof protocol === "number") {
      this.#protocolId = protocol;
      this.#vendorId = 0;
    } else {
      this.#protocolId = protocol.protocolId;
      this.#vendorId = protocol.vendorId;
    }
    this.#protocolSpecificDataAllowed = protocolSpecificDataAllowed;
  }
  encode(message) {
    return super.encode({ ...message, protocolId: this.#protocolId, vendorId: this.#vendorId });
  }
  encodeInternal({ generalStatus, protocolStatus, protocolId, protocolData, vendorId }) {
    const writer = new DataWriter(Endian.Little);
    writer.writeUInt16(generalStatus);
    writer.writeUInt32(vendorId << 16 | protocolId);
    writer.writeUInt16(protocolStatus);
    if (this.#protocolSpecificDataAllowed && protocolData !== void 0 && protocolData.byteLength > 0) {
      writer.writeByteArray(protocolData);
    }
    return writer.toByteArray();
  }
  decodeInternal(bytes) {
    const reader = new DataReader(bytes, Endian.Little);
    const generalStatus = reader.readUInt16();
    const vendorProtocolId = reader.readUInt32();
    const protocolStatus = reader.readUInt16();
    const protocolData = reader.remainingBytesCount > 0 ? reader.remainingBytes : void 0;
    const protocolId = vendorProtocolId & 65535;
    const vendorId = VendorId(vendorProtocolId >>> 16);
    return {
      generalStatus,
      protocolId,
      protocolStatus,
      protocolData,
      vendorId
    };
  }
}
export {
  ProtocolStatusMessageSchema
};
//# sourceMappingURL=ProtocolStatusMessage.js.map
