"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 SetLearnModeMessages_exports = {};
__export(SetLearnModeMessages_exports, {
  LearnModeIntent: () => LearnModeIntent,
  LearnModeStatus: () => LearnModeStatus,
  SetLearnModeCallback: () => SetLearnModeCallback,
  SetLearnModeRequest: () => SetLearnModeRequest,
  SetLearnModeRequestBase: () => SetLearnModeRequestBase,
  SetLearnModeResponse: () => SetLearnModeResponse
});
module.exports = __toCommonJS(SetLearnModeMessages_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 LEARN_MODE_EMPTY_NODE_ID = 239;
var LearnModeIntent;
(function(LearnModeIntent2) {
  LearnModeIntent2[LearnModeIntent2["LegacyStop"] = 0] = "LegacyStop";
  LearnModeIntent2[LearnModeIntent2["LegacyInclusionExclusion"] = 1] = "LegacyInclusionExclusion";
  LearnModeIntent2[LearnModeIntent2["LegacyNetworkWideInclusion"] = 2] = "LegacyNetworkWideInclusion";
  LearnModeIntent2[LearnModeIntent2["LegacyNetworkWideExclusion"] = 3] = "LegacyNetworkWideExclusion";
  LearnModeIntent2[LearnModeIntent2["Stop"] = 128] = "Stop";
  LearnModeIntent2[LearnModeIntent2["Inclusion"] = 129] = "Inclusion";
  LearnModeIntent2[LearnModeIntent2["DirectExclusion"] = 130] = "DirectExclusion";
  LearnModeIntent2[LearnModeIntent2["NetworkWideExclusion"] = 131] = "NetworkWideExclusion";
  LearnModeIntent2[LearnModeIntent2["SmartStart"] = 132] = "SmartStart";
})(LearnModeIntent || (LearnModeIntent = {}));
var LearnModeStatus;
(function(LearnModeStatus2) {
  LearnModeStatus2[LearnModeStatus2["Started"] = 1] = "Started";
  LearnModeStatus2[LearnModeStatus2["ProtocolDone"] = 5] = "ProtocolDone";
  LearnModeStatus2[LearnModeStatus2["Completed"] = 6] = "Completed";
  LearnModeStatus2[LearnModeStatus2["Failed"] = 7] = "Failed";
})(LearnModeStatus || (LearnModeStatus = {}));
let SetLearnModeRequestBase = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Request, import_serial.FunctionType.SetLearnMode), (0, import_serial.priority)(import_core.MessagePriority.Controller)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var SetLearnModeRequestBase2 = class extends _classSuper {
    static {
      __name(this, "SetLearnModeRequestBase");
    }
    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);
      SetLearnModeRequestBase2 = _classThis = _classDescriptor.value;
      if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
      (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
    }
    static from(raw, ctx) {
      if (ctx.origin === import_serial.MessageOrigin.Host) {
        return SetLearnModeRequest.from(raw, ctx);
      } else {
        return SetLearnModeCallback.from(raw, ctx);
      }
    }
  };
  return SetLearnModeRequestBase2 = _classThis;
})();
let SetLearnModeRequest = (() => {
  let _classDecorators = [(0, import_serial.expectedResponse)(import_serial.FunctionType.SetLearnMode)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = SetLearnModeRequestBase;
  var SetLearnModeRequest2 = class extends _classSuper {
    static {
      __name(this, "SetLearnModeRequest");
    }
    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);
      SetLearnModeRequest2 = _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.intent = options.intent;
    }
    static from(_raw, _ctx) {
      throw new import_core.ZWaveError(`${this.name}: deserialization not implemented`, import_core.ZWaveErrorCodes.Deserialization_NotImplemented);
    }
    intent;
    serialize(ctx) {
      this.assertCallbackId();
      this.payload = import_shared.Bytes.from([
        this.intent,
        this.callbackId
      ]);
      return super.serialize(ctx);
    }
    toLogEntry() {
      return {
        ...super.toLogEntry(),
        message: {
          "callback id": this.callbackId ?? "(not set)",
          intent: (0, import_shared.getEnumMemberName)(LearnModeIntent, this.intent)
        }
      };
    }
  };
  return SetLearnModeRequest2 = _classThis;
})();
let SetLearnModeResponse = (() => {
  let _classDecorators = [(0, import_serial.messageTypes)(import_serial.MessageType.Response, import_serial.FunctionType.SetLearnMode)];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_serial.Message;
  var SetLearnModeResponse2 = class extends _classSuper {
    static {
      __name(this, "SetLearnModeResponse");
    }
    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);
      SetLearnModeResponse2 = _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.success = options.success;
    }
    static from(raw, _ctx) {
      const success = raw.payload[0] !== 0;
      return new this({
        success
      });
    }
    success;
    isOK() {
      return this.success;
    }
    toLogEntry() {
      return {
        ...super.toLogEntry(),
        message: { success: this.success }
      };
    }
  };
  return SetLearnModeResponse2 = _classThis;
})();
class SetLearnModeCallback extends SetLearnModeRequestBase {
  static {
    __name(this, "SetLearnModeCallback");
  }
  constructor(options) {
    super(options);
    this.callbackId = options.callbackId;
    this.status = options.status;
    this.assignedNodeId = options.assignedNodeId;
    this.statusMessage = options.statusMessage;
  }
  static from(raw, _ctx) {
    const callbackId = raw.payload[0];
    const status = raw.payload[1];
    const assignedNodeId = raw.payload[2];
    let statusMessage;
    if (raw.payload.length > 3) {
      const msgLength = raw.payload[3];
      statusMessage = raw.payload.subarray(4, 4 + msgLength);
    }
    return new this({
      callbackId,
      status,
      assignedNodeId,
      statusMessage
    });
  }
  status;
  assignedNodeId;
  statusMessage;
  isOK() {
    return this.status !== LearnModeStatus.Failed;
  }
  toLogEntry() {
    const message = {
      "callback id": this.callbackId ?? "(not set)",
      status: (0, import_shared.getEnumMemberName)(LearnModeStatus, this.status)
    };
    if (this.status !== LearnModeStatus.Started || this.assignedNodeId !== LEARN_MODE_EMPTY_NODE_ID) {
      message["assigned node id"] = this.assignedNodeId;
    }
    if (this.statusMessage?.length) {
      message["status message"] = (0, import_shared.buffer2hex)(this.statusMessage);
    }
    return {
      ...super.toLogEntry(),
      message
    };
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  LearnModeIntent,
  LearnModeStatus,
  SetLearnModeCallback,
  SetLearnModeRequest,
  SetLearnModeRequestBase,
  SetLearnModeResponse
});
//# sourceMappingURL=SetLearnModeMessages.js.map
