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

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

//获取当前所在部门
export async function getCurrentDept() {
  return request<RespResult<API.LabelVal>>(
    urlProxyApis(`/operation/handlingCenter/getCurrentDept`),
    {
      method: 'get',
    },
  );
}

//来源统计
export async function getSourceSystemStatistics(params: {
  singleType?: '1' | '2' | any; //1高速，2是普通
}) {
  return request<RespResultList<API.BaseChartInfo>>(
    urlProxyApis(`/operation/handlingCenter/sourceSystemStatistics`),
    {
      method: 'get',
      params,
    },
  );
}

//待办-已办-筛选统计
export async function getHandleFilterOption() {
  return request<RespResultList<API.LabelVal>>(
    urlProxyApis(`/operation/handlingCenter/getHandleFilterOption`),
    {
      method: 'get',
    },
  );
}

//获取待办理操作项
export async function getToDoList(params: {
  singleType?: '1' | '2'; //1高速，2是普通
}) {
  return request<RespResultList<DealAPI.TodoListOptions>>(
    urlProxyApis(
      `/operation/list-event-info/to-do/list-to-do-operation-option`,
    ),
    {
      method: 'get',
      params,
    },
  );
}

//获取已办理操作项
export async function getProcessedList(params: {
  singleType?: '1' | '2'; //1高速，2是普通
}) {
  return request<RespResultList<DealAPI.TodoListOptions>>(
    urlProxyApis(
      `/operation/list-event-info/processed/list-processed-operation-option`,
    ),
    {
      method: 'get',
      params,
    },
  );
}

//待办事件列表
export async function getToDoEventList(
  pageParmas: DealAPI.PageParmas & {
    singleType?: '1' | '2'; //1高速，2是普通
  },
  data: DealAPI.ListReq,
) {
  return request<RespResult<PreEventAPI.List<DealAPI.EventDto>>>(
    urlProxyApis(`/operation/list-event-info/to-do/pages-to-do-event-info`),
    {
      method: 'post',
      params: pageParmas,
      data,
    },
  );
}

//已办事件列表
export async function getProcessedEventList(
  pageParmas: DealAPI.PageParmas & {
    singleType?: '1' | '2'; //1高速，2是普通
  },
  data: DealAPI.ProcessreqListReq,
) {
  return request<RespResult<PreEventAPI.List<DealAPI.EventDto>>>(
    urlProxyApis(
      `/operation/list-event-info/processed/pages-processed-event-info`,
    ),
    {
      method: 'post',
      params: pageParmas,
      data,
    },
  );
}

//获取事件基本信息
export async function getEventInfoDetail(caseId: string) {
  return Promise.all([
    request(
      urlProxyApis(`/operation/event-info-details/event-info-other/${caseId}`),
      {
        method: 'get',
      },
    ), //获取事件基本信息
    request(
      urlProxyApis(
        `/operation/event-info-details/list-event-attachment-info/${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(caseId: string) {
  return request<RespResultList<API.CulationType>>(
    urlProxyApis(
      `/operation/event-info-details/list-event-circulation-record-other/${caseId}`,
    ),
    {
      method: 'get',
    },
  );
}

//立案详情页-查询结案条件
export async function getConditionOptions(registeredConditionCode: string) {
  return request<RespResultList<DealAPI.ConditionOptionsDto>>(
    urlProxyApis(
      `/operation/event-info-details/list-resolution-condition/${registeredConditionCode}`,
    ),
    {
      method: 'get',
    },
  );
}

//派遣详情页-查询处置部门
export async function getDeptOptions() {
  return request<RespResultList<DealAPI.DeptOptions>>(
    urlProxyApis(`/operation/event-info-details/list-disposal-unit`),
    {
      method: 'get',
    },
  );
}

//派遣详情页-查询处置人员
export async function getUserOptions() {
  return request<RespResultList<DealAPI.UserOptions>>(
    urlProxyApis(`/operation/event-info-details/list-disposal-user`),
    {
      method: 'get',
    },
  );
}

//案件办理-某状态下获取操作按钮
export const postCaseBtnOperate = (data: {
  caseStatus: string;
}): Promise<RespResult<any[]>> => {
  return request(
    urlProxyApis(
      '/operation/case-processing/get-button-info-for-case-processing',
    ),
    {
      method: 'post',
      data,
    },
  );
};

//案件办理--正常流程
export const postHandleProcessCase = (
  data: DealAPI.DealCaseProcessDto,
): Promise<RespResult<string>> => {
  return request(
    urlProxyApis('/operation/case-processing/process-universal-case'),
    {
      method: 'post',
      data,
    },
  );
};

//加锁-锁定状态
export const postLockEventStatus = (data: {
  eventId: string;
  caseStatus: string;
}): Promise<RespResult<string>> => {
  return request(
    urlProxyApis('/operation/event-info-details/lock-event-info'),
    {
      method: 'post',
      data,
    },
  );
};

//解锁
export const postUnlockEventStatus = (data: {
  eventIds: string;
}): Promise<RespResult<any>> => {
  return request(
    urlProxyApis('/operation/event-info-details/unlock-event-info'),
    {
      method: 'post',
      data,
    },
  );
};

//案件详情页-获取下一条待办事件
export const processingNextEvent = (data: {
  orderKey?: string;
}): Promise<RespResult<string>> => {
  return request(
    urlProxyApis('/operation/event-info-details/get-next-event-info-id'),
    {
      method: 'post',
      data,
    },
  );
};

//获取已直达详情-指令直达单兵监督信息处置信息
export const getSupervisionInfo = (
  eventId: string,
): Promise<RespResult<DealAPI.SupervisionUserDto>> => {
  return request(
    urlProxyApis(
      `/operation/event-info-details/get-direct-to-single-info/supervision/${eventId}`,
    ),
    {
      method: 'get',
    },
  );
};

//单兵直达-处置人和监督人
export const getSupervisionEventInfo = (
  id: string,
): Promise<RespResult<DealAPI.SupervisionDealDto>> => {
  return request(
    urlProxyApis(`/operation/event-info-details/event-details/${id}`),
    {
      method: 'get',
    },
  );
};

//获取已直达详情-指令直达单兵状态
export const getDisposalStatusInfo = (
  eventId: string,
): Promise<RespResult<DealAPI.DisposalStatusInfoDto>> => {
  return request(
    urlProxyApis(`/operation/event-info-details/get-disposal-info/${eventId}`),
    {
      method: 'get',
    },
  );
};
//获取ai巡查上报列表
export const getMovementSensorEventList = (
data:any
): Promise<any> => {
  return request(
    urlProxyApis(`/movement-sensor-event/page`),
    {
      method: 'get',
      params:data
    },
  );
};
