import { defHttp } from '@/utils/http/axios';
import {
  AccountListGetResultModel,
  AccountParams,
  SaveFormsParams,
  DeleteFormsParams,
  getFormsParams,
} from './model/index';

enum Api {
  GETDESIGNDATA = '/api/FormModule/GetEntityByCode', //获取设计数据
  GETFORMPAGEDATA = '/api/FormScheme/GetFormDataPage?id=', //获取表单分页数据
  SAVEFORMDATA = '/api/FormScheme/SaveForm', //新增编辑自定义表单
  DELFORMSDATA = '/api/FormScheme/DeleteFormData?id=', //删除表单数据
  GETFORMSDATADETAIL = '/api/FormScheme/GetFormData', //表单数据详情
  getFormData = '/api/FormScheme/GetFormData', //获取单行数据
  exportForm = '/api/FormModule/Export?id=', //导出
  DownloadTemplate = '/api/FormScheme/DownTemplateFile?id=', //下载模板
  UploadFile = '/api/Files/Upload', //上传文件
  UploadData = '/api/FormScheme/ImportExcel', //导入
}

/**
 * @description: Get sample options value
 */
export const getFormsDesignData = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel[]>({ url: Api.GETDESIGNDATA, params });
export const getFormsPageData = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel[]>({
    url: Api.GETFORMPAGEDATA + params.id + '&mid=' + params.mid,
    params,
  });
export const saveFormsData = (params: SaveFormsParams) =>
  defHttp.post<AccountListGetResultModel[]>({ url: Api.SAVEFORMDATA, params });
export const delFormsData = (params: DeleteFormsParams) =>
  defHttp.post<AccountListGetResultModel[]>({
    url: Api.DELFORMSDATA + params.id + '&key=' + params.key + '&keyValue=' + params.keyValue,
    params,
  });
export const getFormsDataDetail = (params: DeleteFormsParams) =>
  defHttp.get<AccountListGetResultModel[]>({ url: Api.GETFORMSDATADETAIL, params });
export const getFormData = (params: getFormsParams) => {
  return defHttp.get<AccountListGetResultModel[]>({
    url: `${Api.getFormData}?id=${params.id}&key=${params.key}&keyValue=${params.keyValue}`,
  });
};
export const exportForm = (params: AccountParams) =>
  defHttp.post<AccountListGetResultModel[]>({
    url: Api.exportForm + params.id + '&mid=' + params.mid + '&code=' + params.code,
    responseType: 'blob',
    params,
  });
export const DownloadTemplate = (id: string) => 
  defHttp.get<AccountListGetResultModel[]>({
    url: Api.DownloadTemplate + id,
    responseType: 'blob',
  })
export const uploadFile = (params) => 
  defHttp.post<AccountListGetResultModel[]>({
    url: Api.UploadFile,
    params,
    headers: {
      'Content-type': 'multipart/form-data',
    },
  })
export const uploadData = (params) => 
  defHttp.post<AccountListGetResultModel[]>({
    url: `${Api.UploadData}?id=${params.id}&pkey=${params.pkey}&path=${params.path}`,
  })
