"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 GetSerialApiCapabilitiesMessages_exports = {};
__export(GetSerialApiCapabilitiesMessages_exports, {
  GetSerialApiCapabilitiesRequest: () => GetSerialApiCapabilitiesRequest,
  GetSerialApiCapabilitiesResponse: () => GetSerialApiCapabilitiesResponse
});
module.exports = __toCommonJS(GetSerialApiCapabilitiesMessages_exports);
var import_tslib = require("tslib");
var import_core = require("@zwave-js/core");
var import_serial = require("@zwave-js/serial");
var import_shared = require("@zwave-js/shared");
const NUM_FUNCTIONS = 256;
const NUM_FUNCTION_BYTES = NUM_FUNCTIONS / 8;
let GetSerialApiCapabilitiesRequest = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Request, import_serial.FunctionType.GetSerialApiCapabilities), (0, import_serial.expectedResponse)(import_serial.FunctionType.GetSerialApiCapabilities), (0, import_serial.priority)(import_core.MessagePriority.Controller)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var GetSerialApiCapabilitiesRequest2 = class extends _classSuper {
    static {
      __name(this, "GetSerialApiCapabilitiesRequest");
    }
    static {
      _classThis = this;
    }
    static {
      const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
      (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
      GetSerialApiCapabilitiesRequest2 = _classThis = _classDescriptor.value;
      if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
      (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
    }
  };
  return GetSerialApiCapabilitiesRequest2 = _classThis;
})();
let GetSerialApiCapabilitiesResponse = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Response, import_serial.FunctionType.GetSerialApiCapabilities)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var GetSerialApiCapabilitiesResponse2 = class extends _classSuper {
    static {
      __name(this, "GetSerialApiCapabilitiesResponse");
    }
    static {
      _classThis = this;
    }
    static {
      const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
      (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
      GetSerialApiCapabilitiesResponse2 = _classThis = _classDescriptor.value;
      if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
      (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
    }
    constructor(options) {
      super(options);
      this.firmwareVersion = options.firmwareVersion;
      this.manufacturerId = options.manufacturerId;
      this.productType = options.productType;
      this.productId = options.productId;
      this.supportedFunctionTypes = options.supportedFunctionTypes;
    }
    static from(raw, _ctx) {
      const firmwareVersion = `${raw.payload[0]}.${raw.payload[1]}`;
      const manufacturerId = raw.payload.readUInt16BE(2);
      const productType = raw.payload.readUInt16BE(4);
      const productId = raw.payload.readUInt16BE(6);
      const functionBitMask = raw.payload.subarray(8, 8 + NUM_FUNCTION_BYTES);
      const supportedFunctionTypes = (0, import_core.parseBitMask)(functionBitMask);
      return new this({
        firmwareVersion,
        manufacturerId,
        productType,
        productId,
        supportedFunctionTypes
      });
    }
    firmwareVersion;
    manufacturerId;
    productType;
    productId;
    supportedFunctionTypes;
    serialize(ctx) {
      this.payload = new import_shared.Bytes(8 + NUM_FUNCTION_BYTES);
      const firmwareBytes = this.firmwareVersion.split(".", 2).map((str) => parseInt(str));
      this.payload[0] = firmwareBytes[0];
      this.payload[1] = firmwareBytes[1];
      this.payload.writeUInt16BE(this.manufacturerId, 2);
      this.payload.writeUInt16BE(this.productType, 4);
      this.payload.writeUInt16BE(this.productId, 6);
      const functionBitMask = (0, import_core.encodeBitMask)(this.supportedFunctionTypes, NUM_FUNCTIONS);
      this.payload.set(functionBitMask, 8);
      return super.serialize(ctx);
    }
  };
  return GetSerialApiCapabilitiesResponse2 = _classThis;
})();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  GetSerialApiCapabilitiesRequest,
  GetSerialApiCapabilitiesResponse
});
//# sourceMappingURL=GetSerialApiCapabilitiesMessages.js.map
