import request from '@/axios';

// ==================== 武术赛事赛程选手关联管理接口 ====================

/**
 * 赛程选手关联分页查询
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 * @param {Number} params.scheduleId - 赛程ID
 * @param {Number} params.schedulePlanId - 赛程计划ID（可选）
 * @param {Number} params.athleteId - 运动员ID（可选）
 * @param {Number} params.status - 状态（可选）
 */
export const getScheduleAthleteList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取赛程选手关联详情
 * @param {Number} id - 关联ID
 */
export const getScheduleAthleteDetail = (id) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增赛程选手关联
 * @param {Object} data - 关联数据
 * @param {Number} data.scheduleId - 赛程ID
 * @param {Number} data.schedulePlanId - 赛程计划ID
 * @param {Number} data.athleteId - 运动员ID
 * @param {String} data.athleteName - 运动员姓名
 * @param {Number} data.competitionOrder - 出场顺序
 * @param {Number} data.status - 状态（0待出场1进行中2已完成）
 */
export const addScheduleAthlete = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/save',
    method: 'post',
    data
  })
}

/**
 * 修改赛程选手关联
 * @param {Object} data - 关联数据
 */
export const updateScheduleAthlete = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/update',
    method: 'post',
    data
  })
}

/**
 * 删除赛程选手关联
 * @param {String} ids - 关联ID,多个用逗号分隔
 */
export const removeScheduleAthlete = (ids) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/remove',
    method: 'post',
    params: { ids }
  })
}

/**
 * 批量添加赛程选手
 * @param {Object} data - 批量添加参数
 * @param {Number} data.schedulePlanId - 赛程计划ID
 * @param {Array} data.athleteIds - 运动员ID数组
 * @param {Boolean} data.autoOrder - 是否自动排序（默认true）
 */
export const batchAddScheduleAthletes = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/batch-save',
    method: 'post',
    data
  })
}

/**
 * 自动分配选手到赛程
 * @param {Object} data - 分配参数
 * @param {Number} data.scheduleId - 赛程ID
 * @param {Number} data.projectId - 项目ID
 * @param {String} data.allocateStrategy - 分配策略（random随机/order顺序）
 */
export const autoAllocateAthletes = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/auto-allocate',
    method: 'post',
    data
  })
}

/**
 * 调整选手出场顺序
 * @param {Object} data - 调整参数
 * @param {Number} data.id - 关联ID
 * @param {Number} data.targetOrder - 目标顺序
 */
export const adjustAthleteOrder = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/adjust-order',
    method: 'post',
    data
  })
}

/**
 * 交换两个选手的出场顺序
 * @param {Object} data - 交换参数
 * @param {Number} data.athleteId1 - 选手1的关联ID
 * @param {Number} data.athleteId2 - 选手2的关联ID
 */
export const swapAthleteOrder = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/swap-order',
    method: 'post',
    data
  })
}

/**
 * 随机排序选手出场顺序
 * @param {Number} schedulePlanId - 赛程计划ID
 */
export const randomizeAthleteOrder = (schedulePlanId) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/randomize',
    method: 'post',
    params: { schedulePlanId }
  })
}

/**
 * 更新选手状态
 * @param {Object} data - 状态更新参数
 * @param {Number} data.id - 关联ID
 * @param {Number} data.status - 状态（0待出场1进行中2已完成）
 */
export const updateAthleteStatus = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/update-status',
    method: 'post',
    data
  })
}

/**
 * 获取赛程计划的选手列表（不分页）
 * @param {Number} schedulePlanId - 赛程计划ID
 */
export const getAthletesBySchedulePlan = (schedulePlanId) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/list-by-plan',
    method: 'get',
    params: { schedulePlanId }
  })
}

/**
 * 获取运动员的赛程安排
 * @param {Number} athleteId - 运动员ID
 * @param {Number} competitionId - 赛事ID
 */
export const getAthleteSchedules = (athleteId, competitionId) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/athlete-schedules',
    method: 'get',
    params: { athleteId, competitionId }
  })
}

/**
 * 检查选手时间冲突
 * @param {Object} data - 检查参数
 * @param {Number} data.athleteId - 运动员ID
 * @param {Number} data.schedulePlanId - 赛程计划ID
 */
export const checkAthleteConflict = (data) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/check-conflict',
    method: 'post',
    data
  })
}

/**
 * 签到选手
 * @param {Number} id - 关联ID
 */
export const checkInAthlete = (id) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/check-in',
    method: 'post',
    params: { id }
  })
}

/**
 * 批量签到选手
 * @param {Array} ids - 关联ID数组
 */
export const batchCheckInAthletes = (ids) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/batch-check-in',
    method: 'post',
    data: ids
  })
}

/**
 * 导出赛程选手名单
 * @param {Object} params - 导出参数
 */
export const exportScheduleAthletes = (params) => {
  return request({
    url: '/api/blade-martial/scheduleAthlete/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}
