import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  TournamentsVO,
  TournamentsForm,
  TournamentsQuery,
  TournamentsBindStructuresQuery,
  TournamentsBindStructuresVO
} from '@/api/system/business/tournaments/types';

/**
 * 查询【请填写功能名称】列表
 * @param query
 * @returns {*}
 */

export const listTournaments = (query?: TournamentsQuery): AxiosPromise<TournamentsVO[]> => {
  return request({
    url: '/business/tournaments/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询【请填写功能名称】详细
 * @param id
 */
export const getTournaments = (id: string | number): AxiosPromise<TournamentsVO> => {
  return request({
    url: '/business/tournaments/' + id,
    method: 'get'
  });
};

/**
 * 新增【请填写功能名称】
 * @param data
 */
export const addTournaments = (data: TournamentsForm) => {
  return request({
    url: '/business/tournaments',
    method: 'post',
    data: data
  });
};

/**
 * 修改【请填写功能名称】
 * @param data
 */
export const updateTournaments = (data: TournamentsForm) => {
  return request({
    url: '/business/tournaments',
    method: 'put',
    data: data
  });
};

/**
 * 删除【请填写功能名称】
 * @param id
 */
export const delTournaments = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/' + id,
    method: 'delete'
  });
};

export const getSelectTournamentBlindStructuresList = (query?: TournamentsBindStructuresQuery): AxiosPromise<TournamentsBindStructuresVO[]> => {
  return request({
    url: '/business/tournaments/selectTournamentBlindStructuresList',
    method: 'get',
    params: query
  });
};

/**
 * 分配盲注给赛事
 * @param data 请求数据 { tournamentId, blindStructureIds }
 */
export const assignTournamentBlindStructures = (data: { tournamentId: number; blindStructureIds: number[] }): AxiosPromise<void> => {
  return request({
    url: '/business/tournaments/assignTournamentBlindStructures',
    method: 'post',
    data: data
  });
};

/**
 * 上传 比赛图标
 * @param file 文件
 */
export const uploadTournament = async (file: File) => {
  const formData = new FormData();
  formData.append('file', file); // 后端接收的参数名是 "file"
  const res = await request({
    url: '/business/tournaments/uploadTournament',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });

  return res;
};

/**
 * 删除【请填写功能名称】
 * @param id
 */
export const deleteCheckTournament = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/deleteCheckTournament/' + id,
    method: 'delete'
  });
};

export const closeSendTournament = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/closeSendTournament/' + id,
    method: 'GET'
  });
};

/**
 * 查询 赛事统计相关
 * @param query
 */
export const getStatisticsPageList = (query?: TournamentsQuery): AxiosPromise<TournamentsVO[]> => {
  return request({
    url: '/business/tournaments/getStatisticsPageList',
    method: 'get',
    params: query
  });
};

/**
 * 恢复比赛
 * @param id
 */
export const recoverTournament = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/recoverTournament/' + id,
    method: 'delete'
  });
};

/**
 * 粉碎删除
 * @param id
 */
export const deleteRelationTournament = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/deleteRelationTournament/' + id,
    method: 'delete'
  });
};
export const publishToTournament = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/tournaments/publishToTournament/' + id,
    method: 'get'
  });
};
