import request from '@/utils/request';
import { BaseResponse } from './type';

export interface IncidentItem {
  id?: string; // 
  type?: number; //  事件类型
  level?: number; //  事件等级
  addr?: string; //  地址
  locations?: string; //  经纬度
  createDept?: string; //  上报部门
  source?: string; //  来源
  des?: string; //  事件描述
  pic?: string; //  图片
  video?: string; //  视频
  expr1?: null; // 
  expr2?: null; // 
  exprJson?: null; // 
  name?: string; // 
  status?: number; //  状态
  madinDept?: string; // 
  assistDept?: string; // 
  createBy?: string; // 
  createTime?: string; // 
}

export interface IncidentListResponse extends BaseResponse {
  data?: IncidentItem[];
}

export interface GetIncidentListParams {
  name?: string;
  type?: 1 | 2 | 3 | 4 | 5;
  level?: number | string;
  status?: number | string;
  'params[beginTime]'?: string; // yyyy-MM-dd
  'params[endTime]'?: string; // yyyy-MM-dd
}

/** 事件列表查询 */
export const getIncidentList = (params: GetIncidentListParams) =>
  request<IncidentListResponse>('GET', {
    url: '/zhdd/incident/list',
    params: params,
  });

export interface IncidentItemDetailProcessItem {
  id?: string;
  incidentId?: string;
  des?: string;
  status?: null;
  createTime?: string;
  createBy?: null;
  userRead?: string;
  userUnRead?: string;
  incidentStatus?: number;
}
export interface IncidentItemDetailProcessItemPersonVo {
  id?: string;
  incidentTaskId?: string;
  position?: string;
  person?: string;
}
export interface IncidentItemDetailProcessItemCmdVo {
  command?: string;
  id?: string;
  incidentTaskId?: string;
  index?: number;
}
export interface IncidentItemDetailTaskItem {
  id?: string;
  incidentId?: string;
  taskName?: string;
  taskDes?: string;
  source?: number;
  delFlag?: string;
  createTime?: string;
  createBy?: null;
  taskPersonVos?: IncidentItemDetailProcessItemPersonVo[];
  taskCommandVos?: IncidentItemDetailProcessItemCmdVo[];
}

export interface IncidentItemEmergencyPlan {
  id?: string;
  planId?: string;
  level?: number;
  taskName?: string;
  taskDes?: string;
  createBy?: null;
  createTime?: string;
}

export interface wz {
  availablenum?: string;
  name?: string;
  num?: string;
  time?: string;
  unit?:string;
}

export interface IncidentItemDetail {
  baseInfo?: IncidentItem; // 基本信息
  process?: IncidentItemDetailProcessItem[]; //处置信息
  task?: IncidentItemDetailTaskItem[]; // 处置任务
  baseTask?: Map<string, IncidentItemEmergencyPlan[]>;
  resource?: wz[];
}
export interface IncidentItemDetailResponse extends BaseResponse {
  data: IncidentItemDetail;
}
/** 事件详情 */
export const getIncidentItem = (id: number | string) =>
  request<IncidentItemDetailResponse>('GET', {
    url: `/zhdd/incident/${id}`,
  });

/** 事件接报 */
export const postIncidentItem = (params: IncidentItem) =>
  request<BaseResponse>('POST', {
    url: `/zhdd/incident`,
    data: params,
  });

/**
 * 事件修改
 * ```
 * 如果是更改状态的话，只需要传
 *  { "id":"", "status":xx }
 * ```
 */
export const putIncidentItem = (params: IncidentItem) =>
  request<BaseResponse>('PUT', {
    url: `/zhdd/incident`,
    data: params,
  });

export interface IncidentTaskParam {
  incidentId?: string; // 事件id
  taskName?: string; // 任务名称
  taskDes?: string; // 任务描述
}

/** 添加事件任务 TODO:// 什么接口?? */
export const addIncidentTask = (params: IncidentItem) =>
  request<BaseResponse>('POST', {
    url: `/zhdd/incident/task`,
    data: params,
  });

/** 删除事件任务 TODO:// 什么接口?? ids --> 1,2,3 ?? */
export const deleteIncidentTask = (ids: string) =>
  request<BaseResponse>('DELETE', {
    url: `/zhdd/incident/task/${ids}`,
  });

export interface IncidentProcessParam {
  incidentId?: string; // 事件id
  des?: string; // 处置内容
}

/** 添加处置过程 */
export const AddIncidentProcess = (params: IncidentProcessParam) =>
  request<BaseResponse>('POST', {
    url: `/incidentProcess`,
    data: params,
  });
/** /zhdd/bigscreen/incident/list */

export interface HDIncidentListResponse extends BaseResponse {
  data?: NonNullable<IncidentItem>[];
}

/** 事件详情 */
export const getHDIncidentList = () =>
  request<HDIncidentListResponse>('GET', {
    url: `/zhdd/bigscreen/incident/list`,
  });
