"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ProtocolStatusMessage_exports = {};
__export(ProtocolStatusMessage_exports, {
  ProtocolStatusMessageSchema: () => ProtocolStatusMessageSchema
});
module.exports = __toCommonJS(ProtocolStatusMessage_exports);
var import_general = require("#general");
var import_types = require("#types");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ProtocolStatusMessageSchema extends import_types.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 import_general.DataWriter(import_general.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 import_general.DataReader(bytes, import_general.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 = (0, import_types.VendorId)(vendorProtocolId >>> 16);
    return {
      generalStatus,
      protocolId,
      protocolStatus,
      protocolData,
      vendorId
    };
  }
}
//# sourceMappingURL=ProtocolStatusMessage.js.map
