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

const { createConfirm } = useMessage();

enum Api {
  list = '/stm/es/common/list',
  createDocLib = '/stm/es/common/createDocLib',
  createIndex = '/stm/es/common/createIndex',
  listLabels = '/base.lable/stLable/list',

  createFileDocLib = '/stm/es/file/createDocLib',
  filelist = '/stm/es/file/list',
  queryDocFileById = '/doc/docFiles/queryById',
}

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

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

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

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

/**
 * 创建数据
 * @param params
 */
export const createDocLib = (handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '创建数据',
    content: '确定要创建数据吗？',
    onOk: () => {
      return defHttp.post({ url: Api.createDocLib }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 创建索引
 * @param params
 * @returns
 */

export const createIndex = (handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '创建索引',
    content: '确定要创建索引吗？',
    onOk: () => {
      return defHttp.post({ url: Api.createIndex }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 导入file数据
 * @param handleSuccess
 */
export const createFileDocLib = (handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '创建数据',
    content: '确定要创建数据吗？',
    onOk: () => {
      return defHttp.post({ url: Api.createFileDocLib }).then(() => {
        handleSuccess();
      });
    },
  });
};
