import { defHttp } from '@/utils/http/axios';
import {
  DemoOptionsItem,
  selectParams,
  AccountListGetResultModel,
  AccountParams,
  NoOptionsParam,
  DeiginFormParam,
  DataBaseSqlParam,
  OutKeyParams,
  ImportantDataBaseParam,
} from './model/index';

enum Api {
  FORMSTYPES_LIST = '/api/SysDataItemDetail/Load', //字典
  GETDATABASETABLE_LIST = '/api/SysDatabaseLink/LoadDataBaseLinkTree', //获取数据库
  FORMS_LIST = '/api/FormScheme/LoadFormPage', //查询表单列表
  DATABASE_LIST = '/api/CodeTable/LoadCodeTablePage', //数据对象选择表
  GETIMPORTDATA_FORM = '/api/FormModule/GetTableList', // 查询导入数据表列表
  IMPORTDATABASE_TABLE = '/api/CodeTable/ImportTable?dbCode=', //导入数据表
  OUTKEY_LIST = '/api/CodeTable/GetForms', //获取数据表
  GETBASE_LIST = '/api/FormScheme/GetForm', //获取列表详情
  ADDFORM_DATA = '/api/FormScheme/AddForm', //新增表单设计
  EDITFORM_DATA = '/api/FormScheme/UpdateForm?id=', //编辑表单设计
  ADDSql_DATA = '/api/FormScheme/GetDataColName?dbCode=', // 添加编辑SQL
}
/**
 * @description: Get sample options value
 */
export const getFormsTypeList = (params?: selectParams) =>
  defHttp.get<DemoOptionsItem[]>({ url: Api.FORMSTYPES_LIST, params });

export const getFormGroupList = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.FORMS_LIST, params });
export const getDataBaseTableList = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.DATABASE_LIST, params });
export const getOutKeyList = (params: OutKeyParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.OUTKEY_LIST, params });
export const getBaseConfigList = (params: selectParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.GETBASE_LIST, params });
export const addFormDesignData = (params: DeiginFormParam) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.ADDFORM_DATA, params });
export const editFormDesignData = (params: DeiginFormParam) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.EDITFORM_DATA + params.info.id, params });
export const addFormSqlData = (params: DataBaseSqlParam) =>
  defHttp.post<AccountListGetResultModel>({
    url: Api.ADDSql_DATA + params.dbCode + '&sql=' + params.sql,
    params,
  });
export const getImportBaseTableList = (params: NoOptionsParam) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.GETIMPORTDATA_FORM, params });
export const importDataBaseTable = (params: ImportantDataBaseParam) =>
  defHttp.post<AccountListGetResultModel>({
    url: Api.IMPORTDATABASE_TABLE + params.dbCode,
    params,
  });
export const getDataBaseCodeList = (params: {}) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.GETDATABASETABLE_LIST, params });
