import {
  responsesModel,
  AccountParams,
  FromSortModel,
  LoadFormPageModel,
  FromSchemeInfoModel,
  FromSchemeModel,
  FromSchemandAndInfoModel,
  stateModel,
  schemeModel,
  dataColNameModel,
  schemePageListModel,
  CodeTable_LoadCodeTablePage_Parameters_Model,
  CodeTable_LoadCodeTablePage_Responses_Model,
  CodeTable_GetForms_Parameters_Model,
  CodeTable_GetForms_Responses_Model,
  getTableList_Model,
  CodeTable_ImportTable_Responses_Model,
  ShpLayerSourceLoadPage_Model,
} from './model/formSchemeModel';
import { defHttp } from '@/utils/http/axios';

enum Api {
  // 字典 FormSort
  LoadFormSort = '/api/SysDataItemDetail/Load?code=FormSort',
  AddFormSort = '/api/SysDataItemDetail/Add',
  UpdateFormSort = '/api/SysDataItemDetail/Update',
  DeleteFormSort = '/api/SysDataItemDetail/Delete',

  // 表单设计
  // 查询表单分页信息
  LoadFormPage = '/api/FormScheme/LoadFormPage',
  // LoadFormPage = '/api/FormScheme/LoadFormPage?pageIndex=1&pageSize=10',
  // 新增自定义表单
  AddForm = '/api/FormScheme/AddForm',
  // 获取自定义表单设计数据
  GetForm = '/api/FormScheme/GetForm',
  // 获取自定义表单基本信息
  GetSchemeInfoEntity = '/api/FormScheme/GetSchemeInfoEntity',
  // 更新自定义表单
  UpdateForm = '/api/FormScheme/UpdateForm',
  // 启用或者停用表单
  UpdateState = '/api/FormScheme/UpdateState',
  // 启用或者停用表单
  UpdateScheme = '/api/FormScheme/UpdateScheme',
  // 删除自定义列表
  DeleteForm = '/api/FormScheme/DeleteForm',
  // 获取数据源列表
  GetDataColName = '/api/FormScheme/GetDataColName',
  // 获取自定义表单预览
  GetPreviewForm = '/api/FormScheme/GetPreviewForm',
  // 获取自定义表单模板历史数据
  GetSchemePageList = '/api/FormScheme/GetSchemePageList',
  // 获取表单分页数据
  GetFormDataPage = '/api/FormScheme/GetFormDataPage',
  // 获取表单分页数据
  GetFormDataList = '/api/FormScheme/GetFormDataList',
  // 获取表单数据
  GetFormDataFormScheme = '/api/FormScheme/GetFormData',
  // 保存自定表单数据
  saveForm = '/api/FormScheme/SaveForm',

  // CodeTable 数据对象模型管理
  // 获取CodeTable的分页数据
  Get_LoadCodeTablePage = '/api/CodeTable/LoadCodeTablePage',
  // 获取字典分类列表
  Get_GetEntitys = '/api/CodeTable/GetEntitys',
  // 获取表的对象集合数据
  Get_GetForms = '/api/CodeTable/GetForms',
  // 导入表的数据
  Post_ImportTable = '/api/CodeTable/ImportTable?dbcode=lrsystemdb',
  // 导入获取数据库的表
  Get_GetTableList = '/api/FormModule/GetTableList',
  LoadFormScheme = '/api/FormScheme/LoadFormScheme',

  // 创建表信息
  AddTable = '/api/DbTable/AddTable',
  // 创建字段
  AddColumn = '/api/DbTable/AddColumn',
  // 图斑组件-图层列表
  ShpLayerSourceLoadPage = '/api/ShpLayerSource/LoadPage',
  // 图斑组件-图层列表-图层选择后-查找字段名
  GetTableAndViewColumnList = '/api/CodeTable/GetTableAndViewColumnList',
}

// 字典 FormSort
export function functionLoadFormSort(params: AccountParams) {
  return defHttp.get<FromSortModel>({
    url: Api.LoadFormSort,
    params,
  });
}

export function functionAddFormSort(params: FromSortModel) {
  return defHttp.post({
    url: Api.AddFormSort + '?code=FormSort',
    params,
  });
}

export function functionUpdateFormSort(params: FromSortModel) {
  return defHttp.post({
    url: Api.UpdateFormSort,
    params,
  });
}

export function functionDeleteFormSort(params: AccountParams) {
  return defHttp.post({
    url: Api.DeleteFormSort + '?id=' + params.id,
  });
}

// 表单设计
// 查询表单分页信息
export function functionLoadFormPage(params: LoadFormPageModel) {
  return defHttp.get<FromSchemandAndInfoModel>({
    url: Api.LoadFormPage,
    params,
  });
}

// 新增自定义表单
export function functionAddForm(params: FromSchemandAndInfoModel) {
  return defHttp.post({
    url: Api.AddForm,
    params,
  });
}

// 获取自定义表单设计数据
export function functionGetForm(params: AccountParams) {
  return defHttp.get<FromSchemandAndInfoModel>({
    url: Api.GetForm,
    params,
  });
}

// 获取自定义表单基本信息
export function functionGetSchemeInfoEntity(params: AccountParams) {
  return defHttp.get<FromSchemeInfoModel>({
    url: Api.GetSchemeInfoEntity,
    params,
  });
}

// 更新自定义表单
export function functionUpdateForm(params: AccountParams) {
  return defHttp.post<FromSchemandAndInfoModel>({
    url: Api.UpdateForm + '?id=' + params.info.id,
    params,
  });
}

// 启用或者停用表单
export function functionUpdateState(params: stateModel) {
  return defHttp.post({
    url: Api.UpdateState + '?id=' + params.id + '&state=' + params.state,
  });
}

// 启用或者停用历史表单
export function functionUpdateScheme(params: schemeModel) {
  return defHttp.post({
    url: Api.UpdateScheme + '?id=' + params.id + '&schemeId=' + params.schemeId,
  });
}

// 删除自定义列表
export function functionDeleteForm(params: AccountParams) {
  return defHttp.post({
    url: Api.DeleteForm + '?id=' + params.id,
  });
}

// 获取数据源列表
export function functionGetDataColName(params: dataColNameModel) {
  return defHttp.post({
    url: Api.GetDataColName + '?dbcode=' + params.dbcode + '&sql=' + params.sql,
  });
}

// 获取自定义表单预览
export function functionGetPreviewForm(params: AccountParams) {
  return defHttp.get<FromSchemeModel>({
    url: Api.GetPreviewForm + '?keyValue=' + params.keyValue,
  });
}

// 获取自定义表单模板历史数据
export function functionGetSchemePageList(params: schemePageListModel) {
  return defHttp.get<FromSchemeModel>({
    url: Api.GetSchemePageList,
    params,
  });
}

// CodeTable 数据对象模型管理
// 获取CodeTable的分页数据
export function function_Get_LoadCodeTablePage(
  params: CodeTable_LoadCodeTablePage_Parameters_Model,
) {
  return defHttp.get<CodeTable_LoadCodeTablePage_Responses_Model>({
    url:
      Api.Get_LoadCodeTablePage +
      '?pageIndex=' +
      params.page +
      '&pageSize=' +
      params.limit +
      '&dbCode=' +
      params.dbCode,
  });
}

// // 获取表的对象集合数据
// export function function_Get_GetEntitys() {
//   return defHttp.get<dbtablesForLrsystemModel>({
//     url: Api.Get_GetEntitys,
//   });
// }

// 获取字典分类列表/api/CodeTable/GetForms
export function function_Get_GetForms(params: CodeTable_GetForms_Parameters_Model) {
  return defHttp.get<CodeTable_GetForms_Responses_Model>({
    // url: Api.Get_GetForms + '?dbCode=' + params.dbCode + '&tableNames=' + params.tableNames,
    url: Api.Get_GetForms,
    params,
  });
}

// 导入表的数据
// 获取
export function function_Get_GetTableList() {
  return defHttp.get<getTableList_Model>({
    url: Api.Get_GetTableList,
  });
}
// 导入
export function function_Post_ImportTable(params: CodeTable_ImportTable_Responses_Model) {
  return defHttp.post<responsesModel>({
    url: Api.Post_ImportTable,
    params,
  });
}
// LoadFormScheme
export function LoadFormScheme(params) {
  return defHttp.get({
    url: Api.LoadFormScheme,
    params,
  });
}

// 创建表信息
export function AddTable(params) {
  return defHttp.post({
    url: Api.AddTable + '?dbCode=' + params.dbCode,
    params,
  });
}

// 创建字段
export function AddColumn(params) {
  return defHttp.post({
    url: Api.AddColumn + '?dbCode=' + params.dbCode,
    params: params.dbColumn,
  });
}

// 图斑组件-图层列表
export function ShpLayerSourceLoadPage() {
  return defHttp.get<ShpLayerSourceLoadPage_Model>({
    url: Api.ShpLayerSourceLoadPage,
  });
}

// 图斑组件-图层列表-图层选择后-查找字段名
export function GetTableAndViewColumnList(params) {
  return defHttp.get<CodeTable_GetForms_Responses_Model>({
    url: Api.GetTableAndViewColumnList,
    params,
  });
}

// 获取表单分页数据 【先不写】
export function functionGetFormDataPage(params: AccountParams) {
  return defHttp.post<FromSchemandAndInfoModel>({
    url: Api.GetFormDataPage,
    params,
  });
}
// 获取表单分页数据【先不写】
export function functionGetFormDataList(params: AccountParams) {
  return defHttp.post<FromSchemandAndInfoModel>({
    url: Api.GetFormDataList,
    params,
  });
}

// 获取表单数据【先不写】
export function functionGetFormDataFormScheme(params: AccountParams) {
  return defHttp.get<FromSchemandAndInfoModel>({
    url: Api.GetFormDataFormScheme,
    params,
  });
}

// 保存自定表单数据【先不写】
export function functionsaveForm(params: AccountParams) {
  return defHttp.post<FromSchemandAndInfoModel>({
    url: Api.saveForm,
    params,
  });
}
