"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 Supervision_exports = {};
__export(Supervision_exports, {
  SupervisionCCHooks: () => SupervisionCCHooks
});
module.exports = __toCommonJS(Supervision_exports);
var import_cc = require("@zwave-js/cc");
var import_core = require("@zwave-js/core");
const encapsulateSupervisionCC = {
  transformIncomingCC(controller, self, receivedCC) {
    if (receivedCC instanceof import_cc.SupervisionCCGet) {
      const inner = receivedCC.encapsulated;
      inner.endpointIndex = receivedCC.endpointIndex;
      return inner;
    }
    return receivedCC;
  },
  transformResponse(controller, self, receivedCC, response) {
    if (response.action !== "ok" && response.action !== "fail") {
      return response;
    }
    const supervisionGet = receivedCC.getEncapsulatingCC(import_core.CommandClasses.Supervision);
    if (!supervisionGet)
      return response;
    if (response.action === "fail") {
      const cc2 = new import_cc.SupervisionCCReport({
        // We are not wrapping a CC here
        // eslint-disable-next-line @zwave-js/consistent-mock-node-behaviors
        nodeId: controller.ownNodeId,
        sessionId: supervisionGet.sessionId,
        moreUpdatesFollow: false,
        status: import_core.SupervisionStatus.Fail
      });
      return { action: "sendCC", cc: cc2 };
    }
    if (response.durationMs) {
      const cc2 = new import_cc.SupervisionCCReport({
        // We are not wrapping a CC here
        // eslint-disable-next-line @zwave-js/consistent-mock-node-behaviors
        nodeId: controller.ownNodeId,
        sessionId: supervisionGet.sessionId,
        moreUpdatesFollow: true,
        status: import_core.SupervisionStatus.Working,
        duration: new import_core.Duration(Math.ceil(response.durationMs / 1e3), "seconds")
      });
      return { action: "sendCC", cc: cc2 };
    }
    const cc = new import_cc.SupervisionCCReport({
      // We are not wrapping a CC here
      // eslint-disable-next-line @zwave-js/consistent-mock-node-behaviors
      nodeId: controller.ownNodeId,
      sessionId: supervisionGet.sessionId,
      moreUpdatesFollow: false,
      status: import_core.SupervisionStatus.Success
    });
    return { action: "sendCC", cc };
  }
};
const SupervisionCCHooks = [
  encapsulateSupervisionCC
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SupervisionCCHooks
});
//# sourceMappingURL=Supervision.js.map
