import request from '@/axios';

// ==================== 参赛选手管理接口 ====================

/**
 * 参赛选手分页查询
 * @param {Number} competitionId - 赛事ID
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 */
export const getParticipantList = (competitionId, current, size, params = {}) => {
  return request({
    url: '/api/blade-martial/participant/list',
    method: 'get',
    params: {
      competitionId,
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取参赛选手详情
 * @param {Number} id - 选手主键ID
 */
export const getParticipantDetail = (id) => {
  return request({
    url: '/api/blade-martial/participant/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增参赛选手
 * @param {Object} data - 选手数据
 * @param {Number} data.competitionId - 赛事ID
 * @param {String} data.playerName - 选手姓名
 * @param {Number} data.gender - 性别（1-男，2-女）
 * @param {Number} data.age - 年龄
 * @param {String} data.contactPhone - 联系电话
 * @param {String} data.organization - 所属单位
 * @param {String} data.idCard - 身份证号
 * @param {String} data.projectName - 参赛项目
 * @param {String} data.category - 组别
 * @param {Number} data.orderNum - 出场顺序
 * @param {String} data.introduction - 选手简介
 * @param {Array} data.attachments - 附件列表
 * @param {String} data.remark - 备注
 */
export const addParticipant = (data) => {
  return request({
    url: '/api/blade-martial/participant/save',
    method: 'post',
    data
  })
}

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

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

/**
 * 更新出场顺序
 * @param {Number} id - 选手ID
 * @param {Number} orderNum - 出场顺序
 */
export const updateOrder = (id, orderNum) => {
  return request({
    url: '/api/blade-martial/participant/update-order',
    method: 'post',
    params: { id, orderNum }
  })
}

/**
 * 批量导入参赛选手
 * @param {Number} competitionId - 赛事ID
 * @param {File} file - Excel文件
 */
export const importParticipants = (competitionId, file) => {
  const formData = new FormData()
  formData.append('competitionId', competitionId)
  formData.append('file', file)

  return request({
    url: '/api/blade-martial/participant/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 导出参赛选手名单
 * @param {Number} competitionId - 赛事ID
 */
export const exportParticipants = (competitionId) => {
  return request({
    url: '/api/blade-martial/participant/export',
    method: 'get',
    params: { competitionId },
    responseType: 'blob'
  })
}

/**
 * 批量更新出场顺序
 * @param {Array} data - 选手顺序数据 [{id: 1, orderNum: 1}, {id: 2, orderNum: 2}]
 */
export const batchUpdateOrder = (data) => {
  return request({
    url: '/api/blade-martial/participant/batch-update-order',
    method: 'post',
    data
  })
}
