import {
  GET_SYSTEM_FLOOR_LIST_API,
  GET_SYSTEM_DEVICE_LIST_API,
  GET_SYSTEM_REALTIME_API,
  GET_SYSTEM_DEVICE_POWER_TOGGLE_API
} from "./api";
import instance from "@/util/request";
import apihandler from "@/util/apihandler";

export const getSystemFloors = async (building_tag, sub_system_tag) => {
  const res = await instance.post(GET_SYSTEM_FLOOR_LIST_API, {
    building_tag,
    sub_system_tag,
  });

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

export const getSystemDevices = async ({
  sub_system_tag,
  building_guid,
  department_id_list,
}) => {
  const res = await instance.post(GET_SYSTEM_DEVICE_LIST_API, {
    sub_system_tag,
    building_guid,
    department_id_list,
  });

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

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

export const toggleDevicePower = async ({topic_publish, device_item_id,new_value}) => {
  const res = await instance.post(GET_SYSTEM_DEVICE_POWER_TOGGLE_API, {
    topic_publish,
    device_item_id,
    new_value,
  });

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