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/appPeripheral/serve.ts
var serve_exports = {};
__export(serve_exports, {
  createDeviceConnection: () => createDeviceConnection,
  deleteDevice: () => deleteDevice,
  deleteDeviceConnection: () => deleteDeviceConnection,
  getDeviceBrands: () => getDeviceBrands,
  getDeviceConnectionDetail: () => getDeviceConnectionDetail,
  getDeviceConnections: () => getDeviceConnections,
  getDeviceDetail: () => getDeviceDetail,
  getDeviceTypes: () => getDeviceTypes,
  getDevices: () => getDevices,
  getWorkAreas: () => getWorkAreas,
  markDeviceConnectionConnected: () => markDeviceConnectionConnected,
  markDeviceConnectionDisconnected: () => markDeviceConnectionDisconnected,
  updateDevice: () => updateDevice,
  updateDeviceConnection: () => updateDeviceConnection
});
module.exports = __toCommonJS(serve_exports);
var import_utils = require("../../../utils");
var CONFIG = {
  isPisell2: true
};
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 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
    },
    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", "workarea"]
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var createDeviceConnection = async (payload) => {
  const response = await import_utils.request.getRequest().post("/tenant/device/connection", payload, CONFIG);
  return (response == null ? void 0 : response.data) || null;
};
var getDeviceConnections = async (params) => {
  const response = await import_utils.request.getRequest().get(
    "/tenant/device/connection",
    {
      with: params.with || ["targetDevice.type", "sourceDevice.type", "profiles"],
      type: params.type,
      source_device_id: params.source_device_id,
      target_device_id: params.target_device_id
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var getDeviceConnectionDetail = async (id) => {
  const response = await import_utils.request.getRequest().get(
    `/tenant/device/connection/${id}`,
    {
      with: ["targetDevice.type", "targetDevice.model.brand", "sourceDevice.type", "profiles"]
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var updateDeviceConnection = async (id, payload) => {
  const response = await import_utils.request.getRequest().put(
    `/tenant/device/connection/${id}`,
    payload,
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var deleteDeviceConnection = (id) => import_utils.request.getRequest().remove(`/tenant/device/connection/${id}`, {}, CONFIG);
var markDeviceConnectionConnected = async (id, payload) => {
  const response = await import_utils.request.getRequest().put(
    `/tenant/device/connection/${id}/connected`,
    payload,
    CONFIG
  );
  return (response == null ? void 0 : response.data) || null;
};
var markDeviceConnectionDisconnected = (id) => import_utils.request.getRequest().put(`/tenant/device/connection/${id}/disconnected`, {}, CONFIG);
var getDeviceTypes = async (params) => {
  const response = await import_utils.request.getRequest().get(
    "/tenant/device/type/all",
    {
      with: params.with || ["activeModels", "activeModels.activeProfiles", "activeModels.brand"],
      kind: params.kind
    },
    CONFIG
  );
  return (response == null ? void 0 : response.data) || [];
};
var getDeviceBrands = async () => {
  const response = await import_utils.request.getRequest().get(
    "/api/device_brand:list",
    {
      page: 1,
      pageSize: 20,
      filter: {
        $and: [
          {
            $and: {
              deleted_at: {
                $is: null
              }
            }
          }
        ]
      }
    },
    {
      isNocobase: true,
      headers: {
        "x-data-source": "pisell2"
      }
    }
  );
  return (response == null ? void 0 : response.data) || [];
};
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);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createDeviceConnection,
  deleteDevice,
  deleteDeviceConnection,
  getDeviceBrands,
  getDeviceConnectionDetail,
  getDeviceConnections,
  getDeviceDetail,
  getDeviceTypes,
  getDevices,
  getWorkAreas,
  markDeviceConnectionConnected,
  markDeviceConnectionDisconnected,
  updateDevice,
  updateDeviceConnection
});
