import {
  GET_SYSTEM_FLOOR_LIST_API,
  GET_SYSTEM_DEVICE_LIST_API,
  GET_SYSTEM_REALTIME_API,
  GET_SYSTEM_CONFIG_API,
  POST_MQTT_TOPIC_API,
  POST_MQTT_TOPIC_STOP_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 ({ building_guid }) => {
  const res = await instance.post(GET_SYSTEM_DEVICE_LIST_API, {
    building_guid,
  });

  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 getSystemConfig = async (building_guid) => {
  const res = await instance.post(GET_SYSTEM_CONFIG_API, { building_guid });
  return apiHandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const postMqttTopic = async ({ iotTag, Topic }) => {
  const res = await instance.post(POST_MQTT_TOPIC_API, { iotTag, Topic });

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

export const postMqttTopicStop = async ({ iotTag, Topic }) => {
  const res = await instance.post(POST_MQTT_TOPIC_STOP_API, { iotTag, Topic });

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