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);

// src/plus/saasDevice/devicePlanning/api/devices.ts
var devices_exports = {};
__export(devices_exports, {
  createDevice: () => createDevice,
  deleteDevice: () => deleteDevice,
  getDeviceDetail: () => getDeviceDetail,
  getDevices: () => getDevices,
  isShortNumberUniqueError: () => isShortNumberUniqueError,
  prepareDeviceShortNumber: () => prepareDeviceShortNumber,
  sortDevices: () => sortDevices,
  updateDevice: () => updateDevice
});
module.exports = __toCommonJS(devices_exports);
var import_utils = require("../../../../utils");
var import_shared = require("./shared");
var SHORT_NUMBER_UNIQUE_ERROR = "short_number.unique";
var readFailedCode = (error) => {
  var _a;
  if (!error || typeof error !== "object") return void 0;
  return ((_a = error == null ? void 0 : error.data) == null ? void 0 : _a.failed) || void 0;
};
var getDevices = async (params) => {
  const response = await import_utils.request.getRequest().get(
    "/tenant/device",
    {
      with: params.with || ["type", "model", "workarea"],
      workarea_id: params.workarea_id,
      type_kind: params.type_kind,
      profile_id: params.profile_id,
      structure: params.structure
    },
    import_shared.CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var getDeviceDetail = async (id) => {
  const response = await import_utils.request.getRequest().get(
    `/tenant/device/${id}`,
    {
      with: ["type", "model", "model.activeProfiles", "profile"]
    },
    import_shared.CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var createDevice = async (payload) => {
  const response = await import_utils.request.getRequest().post("/tenant/device", payload, import_shared.CONFIG);
  return (response == null ? void 0 : response.data) || null;
};
var prepareDeviceShortNumber = async () => {
  var _a;
  const response = await import_utils.request.getRequest().get(
    "/tenant/device/prepare",
    {},
    import_shared.CONFIG
  );
  return ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.short_number) || "";
};
var isShortNumberUniqueError = (error) => readFailedCode(error) === SHORT_NUMBER_UNIQUE_ERROR;
var sortDevices = (ids) => import_utils.request.getRequest().post("/tenant/device/sort", { ids }, import_shared.CONFIG);
var updateDevice = async (id, payload) => {
  const response = await import_utils.request.getRequest().put(`/tenant/device/${id}`, payload, import_shared.CONFIG);
  return (response == null ? void 0 : response.data) || null;
};
var deleteDevice = (id) => import_utils.request.getRequest().remove(`/tenant/device/${id}`, {}, import_shared.CONFIG);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createDevice,
  deleteDevice,
  getDeviceDetail,
  getDevices,
  isShortNumberUniqueError,
  prepareDeviceShortNumber,
  sortDevices,
  updateDevice
});
