import { WeaTools } from "ecCom";

const Method = {
  post: "POST",
  get: "GET"
};

const datasource = [
  {
    name: "getFormRightMenus",
    type: Method.post
  },
  {
    name: "getList",
    type: Method.post
  },
  {
    name: "insert",
    type: Method.post
  },
  {
    name: "update",
    type: Method.post
  },
  {
    name: "delete",
    type: Method.post
  },
  {
    name: "getForm",
    type: Method.post
  },
  {
    name: "batchDelete",
    type: Method.post
  },
  {
    name: "getListConditions",
    type: Method.post
  },
  {
    name: "getListRightMenus",
    type: Method.post
  },
  {
    name: "test",
    type: Method.post
  },
  {
    name: "listTest",
    type: Method.post
  },
  {
    name: "getIsCluster",
    type: Method.post
  }
];

const datasourcetype = [
  {
    name: "getFormRightMenus",
    type: Method.post
  },
  {
    name: "getList",
    type: Method.post
  },
  {
    name: "insert",
    type: Method.post
  },
  {
    name: "update",
    type: Method.post
  },
  {
    name: "delete",
    type: Method.post
  },
  {
    name: "getForm",
    type: Method.post
  },
  {
    name: "batchDelete",
    type: Method.post
  },
];

const API = () => {
  const objDatasource = {};
  datasource.map(item => {
    objDatasource[item.name] = params =>
      WeaTools.callApi(
        `/api/integration/datasource/${item.name}`,
        item.type,
        params
      );
  });

  const objDatasourcetype = {};
  datasourcetype.map(item => {
    objDatasourcetype[item.name] = params =>
      WeaTools.callApi(
        `/api/integration/datasourcetype/${item.name}`,
        item.type,
        params
      );
  });

  return {
    datasource: objDatasource,
    datasourcetype: objDatasourcetype
  };
};

export default API();
