import { defHttp } from '@/utils/http/axios';

enum Api {
  // 判读-待审核列表
  LoadCaseInfoLists = 'LoadCaseInfoCheckTuBanList',
  // 判读-详情
  GetCaseInfo = 'GetCaseInfo',
  // 判读-关闭案件
  CloseCaseInfo = 'CloseSingleCaseInfo',
  // 判读-导入数据
  UpdateCaseInfoShpData = '/api/ShpLayerSource/',
  // 判读-新-导入数据
  ImportCaseInfoShpData = '/api/DroneCaseInfoTask/ImportCaseInfoShpData',
  // 判读-根据批次号获取导入数据
  LoadDataBaseInfo = '/api/DroneCaseInfoTask/LoadDataBaseInfo',
  // 判读-获取图层信息
  LoadLayerInfo = '/api/DroneCaseInfoTask/LoadLayerInfo',
  // 判读-添加案件截图任务
  AddCaseInfoTask = '/api/DroneCaseInfoTask/AddCaseInfoTask',
  // 判读-更新案件信息
  UpdateCaseInfoBySubject = '/api/DroneCaseInfoSingle/UpdateCaseInfoBySubject',
  // 判读-获取前后时像信息
  LoadTuBanshixiang = '/api/DroneCaseInfoTask/LoadTuBanshixiang',
  // 判读-根据专题更新案件编号
  UpdateCaseNoBySubject = '/api/DroneCaseInfoSingle/UpdateCaseNoBySubject',
  // 判读-根据用户获取需要查询的任务列表
  LoadDroneCaseInfoTaskByUser = '/api/DroneCaseInfoTask/LoadDroneCaseInfoTaskByUser',
  // 判读-预览最后一次数据
  LoadCaseImportInfoLast = '/api/DroneCaseInfoTask/LoadCaseImportInfoLast',
  // 判读-导出shp文件
  ExportapprovalCaseInfoShapefile = 'ExportapprovalCaseInfoShapefile',
  // 查询是否有复提条件
  IsReSubmit = '/api/DroneCaseInfoSingle/IsReSubmit'
}

const typeObj = {
  '违法用地': '/api/DroneCaseInfoSingle/',
  '非法采矿': '/api/DroneCaseInfoMinerals/',
  '卫片下发': '/api/DroneCaseInfoSatellite/',
  '耕地非粮化': '/api/DroneCaseInfoFLH/',
  '重点问题Ⅰ类': '/api/DroneCaseInfoZdwt1/',
  '重点问题Ⅱ类': '/api/DroneCaseInfoZdwt2/',
  '巡察审计': '/api/DroneCaseInfoXcsj/',
  '生态保护红线监管': '/api/DroneCaseInfoSTHX/',
  '生态修复': '/api/DroneCaseInfoSTXF/',
}
const infoShpData = {
  '违法用地': 'UpdateCaseInfoShpData',
  '非法采矿': 'UpdateCaseInfoShpDataMinerals',
  '卫片下发': 'UpdateCaseInfoShpDataWPXF',
  '耕地非粮化': '',
  '重点问题Ⅰ类': 'UpdateCaseInfoShpDataZDWT1',
  '重点问题Ⅱ类': 'UpdateCaseInfoShpDataZDWT2',
  '巡察审计': '',
}
const closeCaseApi = {
  '违法用地': 'CloseSingleCaseInfo',
  '非法采矿': 'CloseMineralCaseInfo',
  '卫片下发': 'CloseCaseInfoSatellite',
  '耕地非粮化': 'CloseCaseInfoFLH',
  '重点问题Ⅰ类': 'CloseCaseInfoZdwt1',
  '重点问题Ⅱ类': 'CloseCaseInfoZdwt2',
  '巡察审计': 'CloseCaseInfoXCSJ',
  '生态保护红线监管': 'CloseSTHXCaseInfo',
  '生态修复': 'CloseSTXFCaseInfo',
}

export function LoadCaseInfoLists(type, params){
  return defHttp.get({
    url: typeObj[type] + Api.LoadCaseInfoLists,
    params,
  })
}
export function GetCaseInfo(type, params: { id: string }){
  return defHttp.get({
    url: typeObj[type] + Api.GetCaseInfo,
    params,
  })
}
export function CloseCaseInfo(type, params: {id:string, closereason: string}){
  return defHttp.post({
    url: typeObj[type] + closeCaseApi[type],
    data: params,
  })
}
export function UpdateCaseInfoShpData(type, params: {zipFilePath: string, srid: string}){
  return defHttp.post({
    url: `${Api.UpdateCaseInfoShpData}${infoShpData[type]}?zipFilePath=${params.zipFilePath}&srid=${params.srid}`,
    data: params,
  })
}
export function ImportCaseInfoShpData(params: {zipFilePath: string, srid: string, subjectname: string}){
  return defHttp.post({
    url: `${Api.ImportCaseInfoShpData}?zipFilePath=${params.zipFilePath}&srid=${params.srid}&subjectname=${params.subjectname}`,
    data: params,
  })
}
export function LoadDataBaseInfo(params){
  return defHttp.get({
    url: Api.LoadDataBaseInfo,
    params,
  })
}
export function LoadLayerInfo(){
  return defHttp.get({
    url: Api.LoadLayerInfo,
  })
}
export function AddCaseInfoTask(params){
  return defHttp.post({
    url: Api.AddCaseInfoTask,
    data: params,
  })
}
export function UpdateCaseInfoBySubject(params){
  return defHttp.post({
    url: Api.UpdateCaseInfoBySubject,
    data: params,
  })
}
export function LoadTuBanshixiang(){
  return defHttp.get({
    url: Api.LoadTuBanshixiang,
  })
}
export function UpdateCaseNoBySubject (params:{ subject: string, id: string }) {
  return defHttp.post({
    url: Api.UpdateCaseNoBySubject,
    data: params,
  })
}
export function LoadDroneCaseInfoTaskByUser(){
  return defHttp.get({
    url: Api.LoadDroneCaseInfoTaskByUser,
  })
}
export function LoadCaseImportInfoLast(params: { subjectname: string, page?: number, limit?: number }){
  return defHttp.get({
    url: Api.LoadCaseImportInfoLast,
    params
  })
}
export function ExportapprovalCaseInfoShapefile(type, params?){
  let paramsString = new URLSearchParams(params).toString();
  let url = `${typeObj[type] + Api.ExportapprovalCaseInfoShapefile}?${paramsString}`
  return defHttp.post({
    url,
    params,
    responseType: 'blob',
  })
}
export function IsReSubmit(params: { originalcaseno: string, subjectkey: string }){
  return defHttp.get({
    url: Api.IsReSubmit,
    params
  })
}