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

const { createConfirm } = useMessage();

enum Api {
  list = '/doc/docFiles/list',
  save='/doc/docFiles/add',
  edit='/doc/docFiles/edit',
  deleteOne = '/doc/docFiles/delete',
  deleteBatch = '/doc/docFiles/deleteBatch',
  importExcel = '/doc/docFiles/importExcel',
  exportXls = '/doc/docFiles/exportXls',
  checkFileExist = '/doc/docFiles/checkFileExist',

  getDocFileLabels = '/doc/docFiles/getDocFileLabels',

  queryAllList = '/doc/docFiles/queryAllList',
  deleteByName =  '/doc/docFiles/deleteByName',

  addLinkBatch =  '/doc/docFileLink/addBatch',

  findLinkFile =  '/doc/docFileLink/findLinkFile',
  findHistoryByHisid =  '/doc/docFilesHistory/findHistoryByHisid',

}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

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

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess(params.id);
  });
}
export const deleteByName = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteByName, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


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


export const deleteTreeNode = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteTreeNode, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

export const saveOrUpdateTreeNode = (params, isUpdate) => {
  let url = isUpdate ? Api.editTreeNode : Api.saveTreeNode;
  return defHttp.post({ url: url, params });
};

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

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


export const saveFileLink = (params) => {
  return defHttp.post({url: Api.addLinkBatch, params});
}


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


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


