import request from '@/axios';

// ==================== 赛事管理接口 ====================

/**
 * 赛事列表查询
 * @param {Number} current - 当前页
 * @param {Number} size - 每页条数
 * @param {Object} params - 查询参数
 */
export const getCompetitionList = (current, size, params) => {
  return request({
    url: '/api/martial/competition/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取赛事详情
 * @param {Number} id - 赛事ID
 */
export const getCompetitionDetail = (id) => {
  return request({
    url: '/api/martial/competition/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增或修改赛事
 * @param {Object} data - 赛事数据
 * @param {Number} data.id - ID（修改时必传）
 * @param {String} data.competitionName - 赛事名称
 * @param {String} data.competitionCode - 赛事编码
 * @param {String} data.organizer - 主办单位
 * @param {String} data.location - 地区
 * @param {String} data.venue - 详细地点
 * @param {String} data.registrationStartTime - 报名开始时间
 * @param {String} data.registrationEndTime - 报名结束时间
 * @param {String} data.competitionStartTime - 比赛开始时间
 * @param {String} data.competitionEndTime - 比赛结束时间
 * @param {String} data.introduction - 赛事简介
 * @param {String} data.posterImages - 宣传图片(JSON)
 * @param {String} data.contactPerson - 联系人
 * @param {String} data.contactPhone - 联系电话
 * @param {String} data.contactEmail - 联系邮箱
 * @param {String} data.rules - 竞赛规则
 * @param {String} data.requirements - 参赛要求
 * @param {String} data.awards - 奖项设置
 * @param {String} data.regulationFiles - 规程文件(JSON)
 */
export const submitCompetition = (data) => {
  return request({
    url: '/api/martial/competition/submit',
    method: 'post',
    data
  })
}

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

// ==================== 武术赛事订单管理接口 ====================

/**
 * 订单分页查询
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 */
export const getOrderList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/order/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取订单详情
 * @param {Number} id - 订单主键ID
 */
export const getOrderDetail = (id) => {
  return request({
    url: '/api/blade-martial/order/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增订单
 * @param {Object} data - 订单数据
 */
export const addOrder = (data) => {
  return request({
    url: '/api/blade-martial/order/save',
    method: 'post',
    data
  })
}

/**
 * 修改订单
 * @param {Object} data - 订单数据
 */
export const updateOrder = (data) => {
  return request({
    url: '/api/blade-martial/order/update',
    method: 'post',
    data
  })
}

/**
 * 删除订单
 * @param {String} ids - 订单ID,多个用逗号分隔
 */
export const removeOrder = (ids) => {
  return request({
    url: '/api/blade-martial/order/remove',
    method: 'post',
    params: { ids }
  })
}

// ==================== 赛事报名详情接口 ====================

/**
 * 获取报名详情
 * @param {Number} id - 报名详情ID
 */
export const getRegistrationDetail = (id) => {
  return request({
    url: '/api/blade-martial/registration/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 获取参赛人员统计
 * @param {Number} registrationId - 报名详情ID
 */
export const getParticipantList = (registrationId) => {
  return request({
    url: '/api/blade-martial/participant/list',
    method: 'get',
    params: { registrationId }
  })
}

/**
 * 获取项目时间统计
 * @param {Number} registrationId - 报名详情ID
 */
export const getProjectTimeList = (registrationId) => {
  return request({
    url: '/api/blade-martial/project-time/list',
    method: 'get',
    params: { registrationId }
  })
}

/**
 * 获取全额统计
 * @param {Number} registrationId - 报名详情ID
 */
export const getAmountStatsList = (registrationId) => {
  return request({
    url: '/api/blade-martial/amount-stats/list',
    method: 'get',
    params: { registrationId }
  })
}

// ==================== 赛事编排管理接口 ====================

/**
 * 编排分页查询
 * @param {Number} current - 当前页
 * @param {Number} size - 每页条数
 * @param {Object} params - 查询参数
 */
export const getScheduleList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/schedule/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 保存编排
 * @param {Object} data - 编排数据
 */
export const saveSchedule = (data) => {
  return request({
    url: '/api/blade-martial/schedule/save',
    method: 'post',
    data
  })
}

/**
 * 确认完成编排
 * @param {Number} id - 编排ID
 */
export const confirmSchedule = (id) => {
  return request({
    url: '/api/blade-martial/schedule/confirm',
    method: 'post',
    params: { id }
  })
}

// ==================== 调度管理接口 ====================

/**
 * 调度分页查询
 * @param {Number} current - 当前页
 * @param {Number} size - 每页条数
 * @param {Object} params - 查询参数
 */
export const getDispatchList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/dispatch/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 标记完赛
 * @param {Number} id - 调度ID
 */
export const markComplete = (id) => {
  return request({
    url: '/api/blade-martial/dispatch/complete',
    method: 'post',
    params: { id }
  })
}

/**
 * 标记裁判
 * @param {Number} id - 调度ID
 */
export const markReferee = (id) => {
  return request({
    url: '/api/blade-martial/dispatch/referee',
    method: 'post',
    params: { id }
  })
}

// ==================== 场地管理接口 ====================

/**
 * 场地列表查询
 * @param {Number} competitionId - 赛事ID
 */
export const getVenueList = (competitionId) => {
  return request({
    url: '/api/blade-martial/venue/list',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * 新增场地
 * @param {Object} data - 场地数据
 */
export const addVenue = (data) => {
  return request({
    url: '/api/blade-martial/venue/save',
    method: 'post',
    data
  })
}

/**
 * 修改场地
 * @param {Object} data - 场地数据
 */
export const updateVenue = (data) => {
  return request({
    url: '/api/blade-martial/venue/update',
    method: 'post',
    data
  })
}

/**
 * 删除场地
 * @param {String} ids - 场地ID,多个用逗号分隔
 */
export const removeVenue = (ids) => {
  return request({
    url: '/api/blade-martial/venue/remove',
    method: 'post',
    params: { ids }
  })
}
