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

const { createConfirm } = useMessage();

enum Api {
  list = '/act.metric/stMetric/list',
  save='/act.metric/stMetric/add',
  saveRef='/act.metric/stMetric/addRef',
  edit='/act.metric/stMetric/edit',
  deleteOne = '/act.metric/stMetric/delete',
  deleteRef = '/act.metric/stMetric/deleteRef',
  deleteBatch = '/act.metric/stMetric/deleteBatch',
  importExcel = '/act.metric/stMetric/importExcel',
  exportXls = '/act.metric/stMetric/exportXls',
  addFromStMetric ='/metric/metricMonitorSet/addFromStMetric'
}
/**
 * 导出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 deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
export const deleteOneRef = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteRef, 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 saveOrUpdateRef = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.saveRef;
  return defHttp.post({url: url, params});
}

/**
 * 添加到监测库
 * @param params
 */
 export const addFromStMetric = (params) => {
  return defHttp.post({url: Api.addFromStMetric,params});
}
