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/appDevicePlanning/api/index.ts
var api_exports = {};
__export(api_exports, {
  createDevice: () => createDevice,
  createWorkArea: () => createWorkArea,
  deleteDevice: () => deleteDevice,
  deleteWorkArea: () => deleteWorkArea,
  getDeviceModel: () => getDeviceModel,
  getDeviceSetting: () => getDeviceSetting,
  getDeviceTypes: () => getDeviceTypes,
  getDevices: () => getDevices,
  getWorkAreaDetail: () => getWorkAreaDetail,
  getWorkAreas: () => getWorkAreas,
  isShortNumberUniqueError: () => isShortNumberUniqueError,
  linkDevice: () => linkDevice,
  prepareDeviceShortNumber: () => prepareDeviceShortNumber,
  updateDevice: () => updateDevice,
  updateWorkArea: () => updateWorkArea
});
module.exports = __toCommonJS(api_exports);
var import_utils = require("../../../../utils");
var CONFIG = {
  isPisell2: true
};
var SHORT_NUMBER_UNIQUE_ERROR = "short_number.unique";
var readFailedCode = (error) => {
  var _a;
  if (!error || typeof error !== "object") return void 0;
  return ((_a = error.data) == null ? void 0 : _a.failed) || void 0;
};
var getWorkAreas = async () => {
  const response = await import_utils.request.getRequest().get(
    "/tenant/device/workarea",
    {
      relation_count: ["smartDevices", "dumbDevices", "integratedDevices"]
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var createWorkArea = async (payload) => {
  const response = await import_utils.request.getRequest().post(
    "/tenant/device/workarea",
    payload,
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var updateWorkArea = async (id, payload) => {
  const response = await import_utils.request.getRequest().put(
    `/tenant/device/workarea/${id}`,
    payload,
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var deleteWorkArea = (id) => import_utils.request.getRequest().remove(`/tenant/device/workarea/${id}`, {}, CONFIG);
var getWorkAreaDetail = async (params) => import_utils.request.getRequest().get(`/tenant/device/workarea`, params, CONFIG);
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,
      type_code: params.type_code,
      model_code: params.model_code,
      profile_id: params.profile_id
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var getDeviceModel = async (code, withFields = ["type", "brand", "activeProfiles"]) => {
  const response = await import_utils.request.getRequest().get(
    `/tenant/device/model/${code}`,
    {
      with: withFields
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var getDeviceTypes = async (params) => {
  const response = await import_utils.request.getRequest().get(
    "/tenant/device/type/all",
    {
      kind: params.kind,
      with: params.with || ["activeModels", "activeModels.activeProfiles"]
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var createDevice = async (payload) => {
  const response = await import_utils.request.getRequest().post("/tenant/device", payload, 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",
    {},
    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 updateDevice = async (id, payload) => {
  const response = await import_utils.request.getRequest().put(`/tenant/device/${id}`, payload, CONFIG);
  return (response == null ? void 0 : response.data) || null;
};
var deleteDevice = (id) => import_utils.request.getRequest().remove(`/tenant/device/${id}`, {}, CONFIG);
var linkDevice = async (id, data) => {
  const response = await import_utils.request.getRequest().put(
    `/tenant/device/${id}/link`,
    { data },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var getDeviceSetting = async (id, items) => {
  const response = await import_utils.request.getRequest().post(
    `/tenant/device/${id}/setting`,
    { items },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || {};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createDevice,
  createWorkArea,
  deleteDevice,
  deleteWorkArea,
  getDeviceModel,
  getDeviceSetting,
  getDeviceTypes,
  getDevices,
  getWorkAreaDetail,
  getWorkAreas,
  isShortNumberUniqueError,
  linkDevice,
  prepareDeviceShortNumber,
  updateDevice,
  updateWorkArea
});
