import { http } from '@/utils/http/axios';
// import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';
import { LeaderTeamType, TeamAndPersonInfoType } from '@/views/emergency/organization/team-management/type';

/**
 * 查询应急架构体系
 */
export function queryLeaderTeam() {
  return http.request<Omit<LeaderTeamType, 'level'>>({
    url: '/emergencySystem/queryEmergencySystem',
    method: 'get',
  });
}

/**
 * 查询队伍详细信息
 */
export function queryEmergencyTeamDetail(teamId: number) {
  return http.request<TeamAndPersonInfoType>({
    url: `/emergencySystem/queryEmergencyTeamDetail?teamId=${teamId}`,
    method: 'get',
  });
}

export type SetTeamInfoType = {
  id: number;
  memberCount?: number;
  teamName?: string;
  description?: string;
};

/**
 * 保存队伍信息
 */
export function updateEmergencyTeamInfo(data: SetTeamInfoType) {
  return http.request({
    url: `/emergencySystem/updateEmergencyTeamInfo`,
    method: 'post',
    data,
  });
}

export type CreateTeamInfoType = {
  parentId: number;
  teamName: string;
};

/**
 * 创建队伍
 */
export function saveEmergencyTeamInfo(data: CreateTeamInfoType) {
  return http.request({
    url: `/emergencySystem/saveEmergencyTeamInfo`,
    method: 'post',
    data,
  });
}

/**
 * 删除队伍
 */
export function deleteEmergencyTeam(teamId: number) {
  return http.request({
    url: `/emergencySystem/deleteEmergencyTeam?teamId=${teamId}`,
    method: 'post',
  });
}

export type SetPositionType = {
  teamId: number;
  positionList: PositionType[];
};

export type PositionType = {
  id?: number;
  positionLevel: number;
  title: string;
};

/**
 * 获取队伍职位列表
 */
export function queryTeamPositionList(teamId: number) {
  return http.request<PositionType[]>({
    url: `/emergencySystem/queryTeamPositionList?teamId=${teamId}`,
    method: 'get',
  });
}

/**
 * 设置队伍职位
 */
export function saveTeamPosition(data: SetPositionType) {
  return http.request({
    url: `/emergencySystem/saveTeamPosition`,
    method: 'post',
    data,
  });
}

export type AddPersonType = {
  teamId: number;
} & PersonInfoType;

export type PersonInfoType = {
  id?: number;
  userId: number;
  positionId: number | string;
  realname: string;
  staffNo: string;
  mobile: string;
  department: string;
  jobTitle: string;
};

/**
 * 添加/编辑人员，编辑人员需要传id
 */
export function saveTeamPersonnel(data: AddPersonType) {
  return http.request({
    url: `/emergencySystem/saveTeamPersonnel`,
    method: 'post',
    data,
  });
}

/**
 * 从队伍中删除人员
 */
export function deleteTeamPersonnel(personnelId: number) {
  return http.request({
    url: `/emergencySystem/deleteTeamPersonnel?personnelId=${personnelId}`,
    method: 'post',
  });
}
