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

const { createConfirm } = useMessage();

enum Api {
  listCriteria = '/audit/auditCriteria/list',
  save='/audit/auditCriteria/add',
  edit='/audit/auditCriteria/edit',
  deleteOne = '/audit/auditCriteria/delete',
  deleteBatch = '/audit/auditCriteria/deleteBatch',

  listConfig = '/audit/auditCriteriaConfig/list',
  saveConfig='/audit/auditCriteriaConfig/add',
  editConfig='/audit/auditCriteriaConfig/edit',
  deleteOneConfig = '/audit/auditCriteriaConfig/delete',
  deleteBatchConfig = '/audit/auditCriteriaConfig/deleteBatch',
  
  listScores = '/audit/auditCriteriaScores/list',
  saveScores= '/audit/auditCriteriaScores/add',
  editScores='/audit/auditCriteriaScores/edit',
  deleteOneScores = '/audit/auditCriteriaScores/delete',
  deleteBatchScores = '/audit/auditCriteriaScores/deleteBatch',

  computeData = '/audit/auditCriteriaScores/computeData',
  
}


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

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

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();
      });
    }
  });
}

export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

// config

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

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

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

export const saveOrUpdateConfig = (params, isUpdate) => {
  let url = isUpdate ? Api.editConfig : Api.saveConfig;
  return defHttp.post({url: url, params});
}

// Scores

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

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

export const saveOrUpdateScores = (params, isUpdate) => {
  let url = isUpdate ? Api.editScores : Api.saveScores;
  return defHttp.post({url: url, params});
}

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

}



