/**
 * 报名相关API接口
 */

import request from '@/utils/request.js'

export default {
  /**
   * 提交报名订单
   */
  submitRegistration(data) {
    const formattedData = {
      orderNo: data.orderNo,
      competitionId: data.competitionId,
      projectIds: Array.isArray(data.projectIds) ? data.projectIds.join(',') : data.projectIds,
      athleteIds: Array.isArray(data.athleteIds) ? data.athleteIds.join(',') : (data.athleteIds || ''),
      teamIds: Array.isArray(data.teamIds) ? data.teamIds.join(',') : (data.teamIds || ''),
      contactPhone: data.contactPhone,
      totalAmount: data.totalAmount
    }

    console.log('=== API层转换后的数据 ===')
    console.log('订单号:', formattedData.orderNo)
    console.log('projectIds:', formattedData.projectIds)
    console.log('athleteIds:', formattedData.athleteIds)
    console.log('teamIds:', formattedData.teamIds)
    console.log('最终发送到后端的完整数据:', formattedData)

    return request.post('/martial/registrationOrder/submit', formattedData)
  },

  /**
   * 获取报名订单列表
   */
  getRegistrationList(params = {}) {
    return request.get('/martial/registrationOrder/list', {
      current: params.current || 1,
      size: params.size || 10,
      ...params
    })
  },

  /**
   * 获取报名订单详情
   */
  getRegistrationDetail(id) {
    return request.get('/martial/registrationOrder/detail', { id })
  },

  /**
   * 取消报名
   */
  cancelRegistration(ids) {
    return request.post('/martial/registrationOrder/remove', {
      ids: Array.isArray(ids) ? ids.join(',') : ids
    })
  }
}
