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

/**
 * - 预案类型: zhdd_plan_type;
 * - 事件类型: zhdd_incident_type;
 * - 事件状态 + 事件页面右侧菜单: zhdd_incident_status;
 * - 事件等级: zhdd_incident_level;
 * - 事件来源: zhdd_incident_source;
 * - 上报单位 + 归属部门 + 预案页面右侧菜单 : zhdd_org_upload;
 * - 应急资源 + 资源页面右侧菜单:zhdd_resource
 * - 首页标记点: zhdd_screen_type
 * - 车辆类型: zhdd_car_type
 * - 处置方案用户角色: zhdd_incident_task_role
 */
export type DictType =
  | 'zhdd_plan_type'
  | 'zhdd_incident_type'
  | 'zhdd_incident_status'
  | 'zhdd_incident_level'
  | 'zhdd_incident_source'
  | 'zhdd_org_upload'
  | 'zhdd_resource'
  | 'zhdd_screen_type'
  | 'zhdd_car_type'
  | 'zhdd_incident_task_role';

export interface GlobalDict {
  dictLabel: string; // 字典标签
  dictValue: string; // 字典键值
}

export interface DictReponse extends BaseResponse {
  data: GlobalDict[];
}

/** 字典数据查询 */
export const getGlobalDict = (dictType: DictType) =>
  request<DictReponse>('GET', {
    url: `/system/dict/data/type/${dictType}`,
  });

export interface UploadData {
  /** 文件名 */
  fileName?: string;
  /** 文件相对路径 */
  url?: string;
}

export interface UploadReponse extends BaseResponse {
  data: UploadData;
}

export const upload = (file: File) => {
  const form = new FormData();
  form.append('file', file);
  return request<UploadReponse>('POST', {
    url: '/common/upload',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: form,
  });
};

export const getResourcefile = (params: Object) =>
  request<Object>('GET', {
    url: '/common/addlnoow/resource;',
    params: params,
  });






export interface UserInfo {
  userId?: string;
  name?: string;
  userName?: string;
  orgName?: string;
  deptName?: string;
  roles?: string[];
  accessToken: string;
}

export interface UserInfoResponse extends BaseResponse {
  data: UserInfo;
}

export const getUserInfo = (ticket: string) => {
  // debugger
   return request<UserInfoResponse>('GET', {
     url: `${
       import.meta.env.VITE_API_SERVER as string
     }/tpbd-cas/user?ticket=${ticket}`,
     headers: {
       AppId: '3bcb760743ea456faba29a1dfb247bf4',
     },
   });
}
  
 
export const NeedsReadUserName = [
  '武泽义',
  '戈亚武',
  '徐健',
  '邵岩',
  '许辉',
  '周卫东',
  '宋学文',
  '卢勇',
  '李刚',
  '韦宇',
  '解剑铭',
];
export const NeedsReadUser = [
  '4be8a4ea9c574734ab4acb49965b076b', // 武泽义
  'f977a5593521478499f86dd00b2fe5d1', // 戈亚武
  'b30f4e6d73cf49a2a99f85b1d4e5f511', // 徐健
  '41c8d22e9bfa4009bc04eb9c6ee3c3ee', // 邵岩
  '3436050bf856440588bf738a10510515', // 许辉
  'e32c25131b3041c48a2889b5ccc37083', // 周卫东
  '87a4102ce4b84b06bb5232bc2fce7135', // 宋学文
  '1a61ecb94dda4418b32fcf862ca73f55', // 卢勇
  '1f967f07545f43c99c9b175eb161aec8', // 李刚
  '6b61c3e7f972467eb92ef02cd10d2777', // 韦宇
  'a03a481e61674cd2af816db4d35042e5', // 解剑铭
];

export interface NoticeInfoParams {
  msSource: '1';
  msType: '2';
  msNo: string; // 关联的处置过程 id
}

export interface NoticeInfo {
  msTitle?: string;
  msSynopsis?: string;
  msText?: string;
  msSource?: string;
  msType?: string;
  msTime?: string;
  msNo?: string;
  messageReadInfoList?: {
    userId: string;
    /** 阅读状态，0：未读，1：已读 */
    readState: '0' | '1';
  }[];
  fileList: { msAccessoryName?: string; msAccessory?: string }[];
}

export interface NoticeInfoResponse extends BaseResponse {
  rows: NoticeInfo[];
}

export const getMessage = (params: NoticeInfoParams) =>
  request<NoticeInfoResponse>('GET', {
    url: `${
      import.meta.env.VITE_API_SERVER as string
    }/notice-info/messagepushinfo/list`,
    headers: {
      AppId: '3bcb760743ea456faba29a1dfb247bf4',
    },
    params: params,
  });
