import { OptionsDto } from '@/components/TabSwitch';
import { request } from '@umijs/max';
import { RespResult, RespResultList } from './core/ReqData';

/**事件类API
 *
 * @param url 接口地址
 * @returns 预处理
 */
const IS_PROD = process.env.NODE_ENV === 'production' ? true : false;
export const reqBaseUrl = IS_PROD
  ? '/cd-comprehensive/apis/city-preprocessing'
  : '/apis/city-preprocessing';
const urlProxyApis = (url: string) => {
  return `${reqBaseUrl}${url}`;
};

//预处理类型分布统计
export async function queryCountByReportType() {
  return request<RespResultList<API.BaseChartInfo>>(
    urlProxyApis('/pretreatment-statistics/getPretreatmentTypeDistribution'),
    {
      method: 'get',
    },
  );
}

//处理状态筛选
export async function getHandleCountFilterInfo() {
  return request<RespResultList<OptionsDto>>(
    urlProxyApis('/pretreatment-statistics/getHandleCountFilterInfo'),
    {
      method: 'get',
    },
  );
}

//预处理分类状态统计
export async function postPreprocessingTypeStatus(params: {
  pretreatmentState: string | number;
}) {
  return request<RespResultList<OptionsDto>>(
    urlProxyApis('/pretreatment-statistics/preprocessingTypeStatus'),
    {
      method: 'post',
      params,
    },
  );
}

//预处理事件列表
export async function postPreprocessingEventList(
  params: PreEventAPI.PreprocessingReq,
) {
  return request<RespResult<PreEventAPI.List<PreEventAPI.PreprocessingEvent>>>(
    urlProxyApis('/pretreatment-statistics/preprocessingEventList'),
    {
      method: 'post',
      params,
    },
  );
}

//获取预处理事件基本信息和附件信息
export async function getEventInfoDetail(caseId: string) {
  return Promise.all([
    request(urlProxyApis(`/pretreatment-statistics/getEventInfo/${caseId}`), {
      method: 'get',
    }), //获取事件基本信息
    request(
      urlProxyApis(`/pretreatment-statistics/getEventAttachmentInfo/${caseId}`),
      {
        method: 'get',
      },
    ), //获取事件附件
  ]).then((res) => {
    let resetData: any = new Object() as any;
    resetData['eventBase'] = res[0].data;
    resetData['eventAttachment'] = res[1].data;
    return new Promise((resolve) => {
      resolve(resetData);
    });
  });
}

//事件统计-案件流转记录
export async function getCaseCirculationRecord(params: {
  caseId: string;
  pretreatmentType: string;
}) {
  return request<RespResultList<API.CulationType>>(
    urlProxyApis(`/pretreatment-statistics/getPretreatmentHandleInfo`),
    {
      method: 'post',
      params,
    },
  );
}

//交界事件-编辑的基本信息
export async function getEditEventDetailInfo(id: string) {
  return request<RespResult<PreEventAPI.EventBoundaryInfo>>(
    urlProxyApis(
      `/processing-event/borderConfirm/getEditEventDetailInfo/${id}`,
    ),
    {
      method: 'get',
    },
  );
}

//获取区域树
export async function getRegionTree() {
  return request<RespResultList<PreEventAPI.EventTreeDto>>(
    urlProxyApis(`/region-info/getRegionTree`),
    {
      method: 'get',
    },
  );
}

//交界事件-提交信息
export async function updateEventDetailInfo(
  data: PreEventAPI.AdjustBoundaryDto,
) {
  return request<RespResult<boolean>>(
    urlProxyApis(`/processing-event/borderConfirm/updateEventDetailInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//事件合并-编辑的基本信息
export async function getMergeEventInfo(id: string) {
  return request<RespResultList<PreEventAPI.EventDetailDto>>(
    urlProxyApis(`/processing-event/merge/getEditEventDetailInfo/${id}`),
    {
      method: 'get',
    },
  );
}

//事件合并-更新信息
export async function updateMergeEventDetailInfo(
  data: PreEventAPI.UpdateEventMergeDto,
) {
  return request(
    urlProxyApis(`/processing-event/merge/updateEventDetailInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//不明部件-编辑的基本信息
export async function getUnComponentConfirm(id: string) {
  return request<RespResultList<PreEventAPI.EventDetailDto>>(
    urlProxyApis(
      `/processing-event/unComponentConfirm/getEditEventDetailInfo/${id}`,
    ),
    {
      method: 'get',
    },
  );
}

//获取细类的下拉列表
export async function getThirdClassSelection() {
  return request<RespResultList<API.LabelVal>>(
    urlProxyApis(`/classify-info/getThirdClassSelection`),
    {
      method: 'get',
    },
  );
}

//不明部件-更新信息
export async function updateUnComponentConfirm(
  data: PreEventAPI.UpdateUnComponentEventDto,
) {
  return request(
    urlProxyApis(`/processing-event/unComponentConfirm/updateEventDetailInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//获取事件分类标准-部件事件树
export async function getCategoryTree() {
  return request<RespResultList<PreEventAPI.EventTreeDto>>(
    urlProxyApis(`/classify-info/categoryTree`),
    {
      method: 'get',
    },
  );
}

//事件属性补全-编辑的基本信息
export async function getCompletionDetailInfo(id: string) {
  return request<RespResult<PreEventAPI.EventCompletionDetailDto>>(
    urlProxyApis(
      `/processing-event/attributeCompletion/getEditEventDetailInfo/${id}`,
    ),
    {
      method: 'get',
    },
  );
}

//获取点附近专题区域
export async function getPointAroundGrid(
  lon: number | undefined,
  lat: number | undefined,
) {
  return request<RespResult<PreEventAPI.EventCompletionDetailDto>>(
    urlProxyApis(`/thematic-info/getPointAroundGrid/${lon}/${lat}`),
    {
      method: 'get',
    },
  );
}

//事件属性补全-更新信息
export async function updateUnCompletionConfirm(
  data: PreEventAPI.UpdateEventDetailInfoDto,
) {
  return request<RespResult<boolean>>(
    urlProxyApis(`/processing-event/attributeCompletion/updateEventDetailInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//AI事件确认-不正确原因列表
export async function getAiEventWrongReasonList() {
  return request<RespResultList<API.LabelVal>>(
    urlProxyApis(`/processing-event/getAiEventWrongReasonList`),
    {
      method: 'get',
    },
  );
}

//AI事件确认-更新信息
export async function updateAiEventDetailInfo(
  data: PreEventAPI.updateAiEventReq,
) {
  return request<RespResult<boolean>>(
    urlProxyApis(`/processing-event/aiEventConfirm/updateEventDetailInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//上报事件信息
export async function postReportSourceInfo(
  data: PreEventAPI.ReportEventSourceInfoReq,
) {
  return request<RespResult<boolean>>(
    urlProxyApis(`/event-info/reportSourceInfo`),
    {
      method: 'post',
      data,
    },
  );
}

//根据经纬度便捷解析行政区域
export async function getDistrictByLonLat(lon: number, lat: number) {
  return request<RespResultList<PreEventAPI.EventTreeDto>>(
    urlProxyApis(`/region-info/getDistrictByLonLat/${lon}/${lat}`),
    {
      method: 'get',
    },
  );
}

//提级事件
export async function postPromotionEvent(params: { eventId: string }) {
  return request<RespResult<boolean>>(
    urlProxyApis(`/event-info/promotionEvent`),
    {
      method: 'post',
      params,
    },
  );
}

//城管24高速通道列表
//单兵直达事件统计
export async function getDirectStatic(params: {
  disposeType: string;
  type?: 1 | 2 | 3 | undefined;
  time?: string | undefined;
  singleType?: '1' | '2';
}) {
  return request<RespResult<PreEventAPI.CountDbzdDto>>(
    urlProxyApis('/event-info/countDbzd'),
    {
      method: 'post',
      params,
    },
  );
}

//获取单兵直达列表
export async function postDirectList(
  params: {
    singleType?: '1' | '2';//1高速，2是普通
    disposeType: string;
    overdue: string;
    keyWord: string;
  } & DealAPI.PageParmas,
) {
  return request<RespResult<PreEventAPI.List<API.DispatchAllocationItem>>>(
    urlProxyApis('/event-info/dbzdEventList'),
    {
      method: 'post',
      params,
    },
  );
}
