import {
  GET_GRAPH_SIDEBAR_API,
  UPDATE_GRAPH_SIDEBAR_API,
  REMOVE_GRAPH_SIDEBAR_API,
  POST_GRAPH_SIDEBAR_API,
  GET_GRAPH_TABLE_API,
  GET_GRAPH_PARAM_OPTION_API,
  POST_GRAPH_TABLE_API,
  DELETE_GRAPH_TABLE_API,
  POST_GRAPH_TABLE_API_2,
  UPDATE_GRAPH_TABLE_API
} from "./api";
import instance from "@/util/request";
import apihandler from "@/util/apiHandler";

export const getSideBar = async () => {
  const res = await instance.post(GET_GRAPH_SIDEBAR_API);

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

export const addSideBarTreeName = async ({ parent_id, name }) => {
  const res = await instance.post(POST_GRAPH_SIDEBAR_API, { parent_id, name });

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

export const updateSideBarTreeName = async ({ id, name }) => {
  const res = await instance.post(UPDATE_GRAPH_SIDEBAR_API, { id, name });

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

export const removeSideBarTreeName = async (id) => {
  const res = await instance.post(REMOVE_GRAPH_SIDEBAR_API, { id });

  return apihandler(
    res.code,
    { isSuccess: true },
    {
      msg: res.msg,
      code: res.code,
      isSuccess: false,
    }
  );
};

// 中間 table
export const getGraphData = async (id) => {
  const res = await instance.post(GET_GRAPH_TABLE_API, { layer_id: id });

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

export const getGraphAddParamOption = async () => {
  const res = await instance.post(GET_GRAPH_PARAM_OPTION_API);

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

export const addGraphTableData = async (formData) => {
  const res = await instance.post(POST_GRAPH_TABLE_API, formData);

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

export const delGraphData = async (id, hard_delete = false, recover_delete = false) => {
  const res = await instance.post(DELETE_GRAPH_TABLE_API, { id, hard_delete, recover_delete });

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


export const addGraphTableDataWithoutSubSys = async (formData) => {
  const res = await instance.post(POST_GRAPH_TABLE_API_2, formData);

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

export const editGraphTableDataWithoutSubSys = async (formData) => {
  const res = await instance.post(UPDATE_GRAPH_TABLE_API, formData);

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





