import { request } from '../request'

/**
 * 游戏相关接口 步骤
 * 1.GetQuestionByActivityIDAndStatus 抽题时候获取题目大纲信息
 * 2.GetQuestionListDetailRound 获取抽题目详情
 * 3.fetchSubmitQuestionResult点击开始答题后，把基础信息数据传给service
 */

/** 根据活动id查询分组列表，返回队伍分组id和名称是否已经参赛 */
export function fetchGetGroupListByActivityID(id: string, roundType: number = 0) {
  return request<App.Service.Response<Api.Competition.ActivityTeamGroup[]>>({
    url: `/Base/ActivityMain/GetActivity_TeamGroupByMainIDAndStatus?ActivityID=${id}&RoundType=${roundType}`,
    method: 'get',
  })
}

/** 抽题时候获取题目大纲信息 */
export function fetchGetQuestionOutline(ActivityID: number, status: number = 0) {
  return request<App.Service.Response<Api.Competition.QuestionListRecord[]>>({
    url: `/Base/ActivityMain/GetQuestionByActivityIDAndStatus/?ActivityID=${ActivityID}&status=${status}`,
    method: 'post',
    data: {
      ActivityID,
      status,
    },
  })
}

/** 抽题目详情 */
export function fetchGetQuestionDetail(ActivityID: string, questionID: number) {
  return request<App.Service.Response<Api.Competition.QuestionListDetailRound>>({
    url: `/Base/ActivityMain/GetQuestionListDetailRound/?MainID=${ActivityID}&questionID=${questionID}`,
    method: 'post',
    data: {
      MainID: ActivityID,
      questionID,
    },
  })
}

/** 提交抽题结果 */
export function fetchSubmitQuestionResult(data: Api.Competition.QuestionAddParams) {
  return request<App.Service.Response<Api.Competition.QuestionListDetailRound>>({
    url: `/Base/ActivityMain/AddActivity_TeamQuestionUse/?RoomID=${data.RoomID}&MainID=${data.MainID}&TeamGroupID=${data.TeamGroupID}&QuestionID=${data.QuestionID}&QuestionDetaiID=${data.QuestionDetaiID}&TeamGroupQuestionID=${data.TeamGroupQuestionID}`,
    method: 'post',
    data,
  })
}

/** 获取游戏现场统计结果 */
export function fetchGetGameStatistics(data: { TeamGroupID: number, QuestionID: number }) {
  return request<App.Service.Response<Api.Competition.TeamAnswerData[]>>({
    url: `/Base/ActivityMain/GetTeamQuestionUseByTeamGroupIDAndQuestionID/?TeamGroupID=${data.TeamGroupID}&QuestionID=${data.QuestionID}`,
    method: 'post',
    data,
  })
}

/** 获取游戏现场问题 */
export function fetchGetCurrentQuestion(data: Api.Competition.GetCurrentQuestionParams) {
  return request<App.Service.Response<Api.Competition.CurrentQuestionResponse>>({
    url: `/Base/ActivityMain/GetCurrentQuestion/?ActivityID=${data.ActivityID}&GroupID=${data.GroupID}&RoundType=${data.RoundType}`,
    method: 'post',
    data,
  })
}

/** 定时刷，评委是否评完结果 判断是否可以下一步 */
export function fetchCheckNextStep(TeamGroup_QuestionID: number) {
  return request<App.Service.Response<any>>({
    url: `/Base/ActivityMain/GetCurrentQuestionUse/?TeamGroup_QuestionID=${TeamGroup_QuestionID}`,
    method: 'post',
    data: {
      TeamGroup_QuestionID,
    },
  })
}

/** 根据活动id查询题目列表 */
export function fetchGetQuestionTableByActivityID(ActivityID: string, RoundType: number = 0) {
  return request<App.Service.Response<Api.Competition.QuestionListDetailRound[]>>({
    url: `/Base/ActivityMain/GetActivity_QuestionTableByActivityID/?ID=${ActivityID}&RoundType=${RoundType}`,
    method: 'get',
  })
}

/** 根据 roomid查询当前正在比赛的题目 */
export function fetchGetCurrentQuestionByRoomID(RoomID: number) {
  return request<App.Service.Response<Api.Competition.GetCurrentQuestionInfo>>({
    url: `/Base/ActivityMain/SelectTask?RoomID=${RoomID}`,
    method: 'post',
    data: {
      RoomID,
    },
  })
}

/** 根据QuestionDetaiID查询题目详情 */
export function fetchGetQuestionDetailByID(QuestionDetailID: number) {
  return request<App.Service.Response<Api.Competition.QuestionListDetailRound>>({
    url: `/Base/ActivityMain/GetQuestionListDetailByID/?QuestionID=${QuestionDetailID}`,
    method: 'get',
  })
}

/** 加时赛选择组小队 */
export function fetchAddExtraTime(data: Api.Competition.AddExtraTimeParams) {
  return request<App.Service.Response<any>>({
    url: `/Base/ActivityMain/AddOverTimeTeamGroup`,
    method: 'post',
    data,
  })
}
