"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 GetNodeProtocolInfoMessages_exports = {};
__export(GetNodeProtocolInfoMessages_exports, {
  GetNodeProtocolInfoRequest: () => GetNodeProtocolInfoRequest,
  GetNodeProtocolInfoResponse: () => GetNodeProtocolInfoResponse
});
module.exports = __toCommonJS(GetNodeProtocolInfoMessages_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");
var import_typeguards = require("alcalzone-shared/typeguards");
let GetNodeProtocolInfoRequest = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Request, import_serial.FunctionType.GetNodeProtocolInfo), (0, import_serial.expectedResponse)(import_serial.FunctionType.GetNodeProtocolInfo), (0, import_serial.priority)(import_core.MessagePriority.Controller)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var GetNodeProtocolInfoRequest2 = class extends _classSuper {
    static {
      __name(this, "GetNodeProtocolInfoRequest");
    }
    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);
      GetNodeProtocolInfoRequest2 = _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.requestedNodeId = options.requestedNodeId;
    }
    static from(raw, ctx) {
      const requestedNodeId = (0, import_core.parseNodeID)(raw.payload, ctx.nodeIdType, 0).nodeId;
      return new this({
        requestedNodeId
      });
    }
    // This must not be called nodeId or the message will be treated as a node query
    // but this is a message to the controller
    requestedNodeId;
    serialize(ctx) {
      this.payload = (0, import_core.encodeNodeID)(this.requestedNodeId, ctx.nodeIdType);
      return super.serialize(ctx);
    }
  };
  return GetNodeProtocolInfoRequest2 = _classThis;
})();
let GetNodeProtocolInfoResponse = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Response, import_serial.FunctionType.GetNodeProtocolInfo)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var GetNodeProtocolInfoResponse2 = class extends _classSuper {
    static {
      __name(this, "GetNodeProtocolInfoResponse");
    }
    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);
      GetNodeProtocolInfoResponse2 = _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.isListening = options.isListening;
      this.isFrequentListening = options.isFrequentListening;
      this.isRouting = options.isRouting;
      this.supportedDataRates = options.supportedDataRates;
      this.protocolVersion = options.protocolVersion;
      this.optionalFunctionality = options.optionalFunctionality;
      this.nodeType = options.nodeType;
      this.supportsSecurity = options.supportsSecurity;
      this.supportsBeaming = options.supportsBeaming;
      this.basicDeviceClass = options.basicDeviceClass;
      this.genericDeviceClass = options.genericDeviceClass;
      this.specificDeviceClass = options.specificDeviceClass;
    }
    static from(raw, ctx) {
      let isLongRange = false;
      const requestContext = ctx.requestStorage?.get(import_serial.FunctionType.GetNodeProtocolInfo);
      if ((0, import_typeguards.isObject)(requestContext) && "nodeId" in requestContext && typeof requestContext.nodeId === "number") {
        isLongRange = (0, import_core.isLongRangeNodeId)(requestContext.nodeId);
      }
      const { hasSpecificDeviceClass, ...rest } = (0, import_core.parseNodeProtocolInfo)(raw.payload, 0, isLongRange);
      const isListening = rest.isListening;
      const isFrequentListening = rest.isFrequentListening;
      const isRouting = rest.isRouting;
      const supportedDataRates = rest.supportedDataRates;
      const protocolVersion = rest.protocolVersion;
      const optionalFunctionality = rest.optionalFunctionality;
      const nodeType = rest.nodeType;
      const supportsSecurity = rest.supportsSecurity;
      const supportsBeaming = rest.supportsBeaming;
      const basicDeviceClass = raw.payload[3];
      const genericDeviceClass = raw.payload[4];
      const specificDeviceClass = hasSpecificDeviceClass ? raw.payload[5] : 0;
      return new this({
        isListening,
        isFrequentListening,
        isRouting,
        supportedDataRates,
        protocolVersion,
        optionalFunctionality,
        nodeType,
        supportsSecurity,
        supportsBeaming,
        basicDeviceClass,
        genericDeviceClass,
        specificDeviceClass
      });
    }
    /** Whether this node is always listening or not */
    isListening;
    /** Indicates the wakeup interval if this node is a FLiRS node. `false` if it isn't. */
    isFrequentListening;
    /** Whether the node supports routing/forwarding messages. */
    isRouting;
    supportedDataRates;
    protocolVersion;
    /** Whether this node supports additional CCs besides the mandatory minimum */
    optionalFunctionality;
    /** Whether this node is a controller (can calculate routes) or an end node (relies on route info) */
    nodeType;
    /** Whether this node supports security (S0 or S2) */
    supportsSecurity;
    /** Whether this node can issue wakeup beams to FLiRS nodes */
    supportsBeaming;
    basicDeviceClass;
    genericDeviceClass;
    specificDeviceClass;
    serialize(ctx) {
      const protocolInfo = (0, import_core.encodeNodeProtocolInfo)({
        isListening: this.isListening,
        isFrequentListening: this.isFrequentListening,
        isRouting: this.isRouting,
        supportedDataRates: this.supportedDataRates,
        protocolVersion: this.protocolVersion,
        optionalFunctionality: this.optionalFunctionality,
        nodeType: this.nodeType,
        supportsSecurity: this.supportsSecurity,
        supportsBeaming: this.supportsBeaming,
        hasSpecificDeviceClass: this.specificDeviceClass !== 0
      });
      this.payload = import_shared.Bytes.concat([
        protocolInfo,
        [
          this.basicDeviceClass,
          this.genericDeviceClass,
          this.specificDeviceClass
        ]
      ]);
      return super.serialize(ctx);
    }
  };
  return GetNodeProtocolInfoResponse2 = _classThis;
})();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  GetNodeProtocolInfoRequest,
  GetNodeProtocolInfoResponse
});
//# sourceMappingURL=GetNodeProtocolInfoMessages.js.map
