import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GameTeamVO, GameTeamForm, GameTeamQuery } from '@/api/system/gameTeam/types';

/**
 * 查询参赛队伍列表
 * @param query
 * @returns {*}
 */

export const listGameTeam = (query?: GameTeamQuery): AxiosPromise<GameTeamVO[]> => {
  return request({
    url: '/system/gameTeam/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询参赛队伍详细
 * @param teamId
 */
export const getGameTeam = (teamId: string | number): AxiosPromise<GameTeamVO> => {
  return request({
    url: '/system/gameTeam/' + teamId,
    method: 'get'
  });
};

/**
 * 新增参赛队伍
 * @param data
 */
export const addGameTeam = (data: GameTeamForm) => {
  return request({
    url: '/system/gameTeam',
    method: 'post',
    data: data
  });
};

/**
 * 修改参赛队伍
 * @param data
 */
export const updateGameTeam = (data: GameTeamForm) => {
  return request({
    url: '/system/gameTeam',
    method: 'put',
    data: data
  });
};

/**
 * 删除参赛队伍
 * @param teamId
 */
export const delGameTeam = (teamId: string | number | Array<string | number>) => {
  return request({
    url: '/system/gameTeam/' + teamId,
    method: 'delete'
  });
};

/**
 * 查询参赛队伍数量
 * @returns {*}
 */
export const getTeamCount = () => {
  return request({
    url: '/system/gameTeam/count',
    method: 'get'
  });
};

/**
 * 更新队伍中的运动员列表
 * @param teamId 队伍ID
 * @param athleteIds 运动员ID列表
 */
export const updateTeamAthletes = (teamId: string | number, athleteIds: Array<string | number>) => {
  return request({
    url: '/system/gameTeam/updateAthletes',
    method: 'put',
    data: {
      teamId,
      athleteIds
    }
  });
};

/**
 * 批量更新队伍的排名分组
 * @param teamIds 队伍ID列表
 */
export const moveGroup = (data: { teamIds: (string | number)[], rgId: number }) => {
  return request({
    url: '/system/gameTeam/moveGroup',
    method: 'put',
    data: data
  });
};
