import {
  GET_BUILDING_API,
  GET_AUTHPAGE_API,
  GET_SUBAUTHPAGE_API,
  GET_ALL_DEVICE_API,
} from "./api";
import instance from "@/util/request";
import apihandler from "@/util/apihandler";

export const getBuildings = async () => {
  const res = await instance.post(GET_BUILDING_API);

  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const getAuth = async () => {
  const res = await instance.post(GET_AUTHPAGE_API);
  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const getAllSysSidebar = async () => {
  const res = await instance.post(GET_SUBAUTHPAGE_API, {
    building_tag: "",
  });
  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const getSysSidebar = async (building_tag) => {
  const res = await instance.post(GET_SUBAUTHPAGE_API, {
    building_tag,
  });

  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const getAllDevice = async () => {
  const res = await instance.post(GET_ALL_DEVICE_API);

  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const ackSingleAlarm = async (uuid) => {
  const res = await instance.post(
    `/obix/alarm/${uuid}/ack`,
    '<obj is="obix:AckAlarmIn"><str name="ackUser" val="obix" /></obj>'
  );
  console.log("acked", res);
  return apihandler(res.code, res, {
    msg: res.msg,
    code: res.code,
  });
};
