import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {

  complianeInfoList = '/audit/complianeInfoList',
  complianeItemList = '/audit/complianeItemList',
  queryAllStComplianeItems =  '/audit/queryAllStComplianeItems',
  saveRelation = "/audit/saveActRelations",
  queryActRelates = "/audit/queryActRelates",
  deleteActRel = "/audit/deleteActRel",
  saveBatchActRelations = '/audit/saveBatchActRelations',
  saveBatchLabels = '/audit/stLabelRelLib/batchAdd',
  queryAllLabels = '/base.lable/stLable/queryAllData',
  mergeAct = '/audit/auditAct/mergeAct',
  queryDocFileById =  '/doc/docFiles/queryById',

  queryActByIds = '/audit/auditAct/queryActByIds',
  queryLabelByCodes = '/audit/queryLabelByCodes',

  queryAllDataReport = '/audit/report/queryAllDataReport'

}

const DelBatchApi = {
  1:'/audit/auditComplianeItem/deleteBatch',
  2:'/audit/auditInnerCtrl/deleteBatch',
  3:'/audit/auditInnerOrder/deleteBatch',
  4:'/audit/auditProblem/deleteBatch',
  5:'/audit/auditCheckMethod/deleteBatch',
  6:'/audit/auditRiskEvent/deleteBatch',
  7:'/audit/auditBestPractice/deleteBatch',
  8:'/audit/auditRiskScenario/deleteBatch',
  9:'/audit/auditAct/deleteBatch',
  10:'/base.lable/stLable/deleteBatch',
}

const  saveNewApi= {
  1:'/audit/auditComplianeItem/add',
  2:'/audit/auditInnerCtrl/add',
  3:'/audit/auditInnerOrder/add',
  4:'/audit/auditProblem/add',
  5:'/audit/auditCheckMethod/add',
  6:'/audit/auditRiskEvent/add',
  7:'/audit/auditBestPractice/add',
  8:'/audit/auditRiskScenario/add',
  9:'/audit/auditAct/add',
  10:'/base.lable/stLable/add',
}

const saveEditApi = {
  1:'/audit/auditComplianeItem/edit',
  2:'/audit/auditInnerCtrl/edit',
  3:'/audit/auditInnerOrder/edit',
  4:'/audit/auditProblem/edit',
  5:'/audit/auditCheckMethod/edit',
  6:'/audit/auditRiskEvent/edit',
  7:'/audit/auditBestPractice/edit',
  8:'/audit/auditRiskScenario/edit',
  9:'/audit/auditAct/edit',
  10:'/base.lable/stLable/edit',
}

const deletehApi = {
  1:'/audit/auditComplianeItem/delete',
  2:'/audit/auditInnerCtrl/delete',
  3:'/audit/auditInnerOrder/delete',
  4:'/audit/auditProblem/delete',
  5:'/audit/auditCheckMethod/delete',
  6:'/audit/auditRiskEvent/delete',
  7:'/audit/auditBestPractice/delete',
  8:'/audit/auditRiskScenario/delete',
  9:'/audit/auditAct/delete',
  10:'/base.lable/stLable/delete',
}


export const saveRelation = (params) => {
  return defHttp.get({url: Api.saveRelation, params});
}
export const saveBatchActRels = (params) => {
  return defHttp.get({url: Api.saveBatchActRelations, params});
}

export const getComplianeInfoList = (params) => {
  return  defHttp.get({url: Api.complianeInfoList, params});
}


export const queryAllLabels = (params) => {
  return  defHttp.get({url: Api.queryAllLabels, params});
}


export const getComplianeItemList = (params) => {
  return  defHttp.get({url: Api.complianeItemList, params});
}

export const queryAllStComplianeItems = (params) => {
  return  defHttp.get({url: Api.queryAllStComplianeItems, params});
}

export const queryActRelates = (params) => {
  return  defHttp.get({url: Api.queryActRelates, params});
}


export const deleteByTp = (tp,params,handleSuccess) => {
  return defHttp.delete({url: deletehApi[tp], params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const deleteActRel = (params) => {
  return  defHttp.get({url: Api.deleteActRel, params});
}


export const batchActDeleteByTp = (tp,params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: DelBatchApi[tp], data: params}, {joinParamsToUrl: true}).then(() => {
        
        handleSuccess();
      });
    }
  });
}


export const saveBatchLabels = (params) => {
  return defHttp.get({url: Api.saveBatchLabels,params}).then(() => { });
}

export const mergeAct = (params) => {
  return defHttp.get({url: Api.mergeAct, params});
}


export const queryDocFileById = (params) => {
  return defHttp.get({url: Api.queryDocFileById, params});
}


export const saveOrUpdateByTp = (tp,params, isUpdate) => {
  let url = isUpdate ? saveEditApi[tp] : saveNewApi[tp];
  return defHttp.post({url: url, params});
}

export const queryActByIds = (params) => {
  return defHttp.get({url: Api.queryActByIds, params});
}

export const queryLabelByCodes = (params) => {
  return defHttp.get({url: Api.queryLabelByCodes, params});
}

export const queryAllDataReport = (params) => {
  return defHttp.get({url: Api.queryAllDataReport, params});
}



