import request from '@/axios';

// ==================== 武术赛事裁判邀请管理接口 ====================

/**
 * 裁判邀请分页查询
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 * @param {Number} params.competitionId - 赛事ID
 * @param {String} params.judgeName - 裁判姓名（可选）
 * @param {String} params.judgeLevel - 裁判等级（可选）
 * @param {Number} params.inviteStatus - 邀请状态（可选）
 */
export const getJudgeInviteList = (current, size, params) => {
  return request({
    url: '/api/martial/judgeInvite/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取裁判邀请详情
 * @param {Number} id - 邀请ID
 */
export const getJudgeInviteDetail = (id) => {
  return request({
    url: '/api/martial/judgeInvite/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 发送邀请
 * @param {Object} data - 邀请数据
 * @param {Number} data.competitionId - 赛事ID
 * @param {String} data.judgeName - 裁判姓名
 * @param {String} data.judgeLevel - 裁判等级
 * @param {String} data.contactPhone - 联系电话
 * @param {String} data.contactEmail - 联系邮箱
 * @param {String} data.inviteMessage - 邀请信息（可选）
 */
export const sendInvite = (data) => {
  return request({
    url: '/api/martial/judgeInvite/send',
    method: 'post',
    data
  })
}

/**
 * 修改邀请
 * @param {Object} data - 邀请数据
 */
export const updateInvite = (data) => {
  return request({
    url: '/api/martial/judgeInvite/submit',
    method: 'post',
    data
  })
}

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

/**
 * 批量发送邀请
 * @param {Object} data - 批量邀请参数
 * @param {Number} data.competitionId - 赛事ID
 * @param {Array} data.judges - 裁判信息数组
 * @param {String} data.inviteMessage - 邀请信息（可选）
 */
export const batchSendInvites = (data) => {
  return request({
    url: '/api/martial/judgeInvite/batch-send',
    method: 'post',
    data
  })
}

/**
 * 重新发送邀请
 * @param {Number} id - 邀请ID
 */
export const resendInvite = (id) => {
  return request({
    url: `/api/martial/judgeInvite/resend/${id}`,
    method: 'post'
  })
}

/**
 * 裁判回复邀请
 * @param {Object} data - 回复数据
 * @param {Number} data.inviteId - 邀请ID
 * @param {String} data.inviteToken - 邀请令牌
 * @param {Number} data.replyStatus - 回复状态（1接受2拒绝）
 * @param {String} data.replyNote - 回复备注
 */
export const replyInvite = (data) => {
  return request({
    url: '/api/martial/judgeInvite/reply',
    method: 'post',
    data
  })
}

/**
 * 取消邀请
 * @param {Number} id - 邀请ID
 * @param {String} reason - 取消原因
 */
export const cancelInvite = (id, reason) => {
  return request({
    url: `/api/martial/judgeInvite/cancel/${id}`,
    method: 'post',
    params: { reason }
  })
}

/**
 * 确认邀请
 * @param {Number} id - 邀请ID
 */
export const confirmInvite = (id) => {
  return request({
    url: `/api/martial/judgeInvite/confirm/${id}`,
    method: 'post'
  })
}

/**
 * 获取邀请统计
 * @param {Number} competitionId - 赛事ID
 */
export const getInviteStatistics = (competitionId) => {
  return request({
    url: '/api/martial/judgeInvite/statistics',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * 获取已接受邀请的裁判列表
 * @param {Number} competitionId - 赛事ID
 */
export const getAcceptedJudges = (competitionId) => {
  return request({
    url: '/api/martial/judgeInvite/accepted-judges',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * 从裁判库导入
 * @param {Number} competitionId - 赛事ID
 * @param {String} judgeIds - 裁判ID（逗号分隔）
 */
export const importFromJudgePool = (competitionId, judgeIds) => {
  return request({
    url: '/api/martial/judgeInvite/import/pool',
    method: 'post',
    params: { competitionId, judgeIds }
  })
}

/**
 * 导出邀请名单
 * @param {Object} params - 导出参数
 */
export const exportInvites = (params) => {
  return request({
    url: '/api/martial/judgeInvite/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

/**
 * 发送提醒消息
 * @param {Number} id - 邀请ID
 * @param {String} message - 提醒消息
 */
export const sendReminder = (id, message) => {
  return request({
    url: `/api/martial/judgeInvite/reminder/${id}`,
    method: 'post',
    params: { message }
  })
}

/**
 * 生成邀请码
 * @param {Object} data - 生成参数
 * @param {Number} data.competitionId - 赛事ID
 * @param {Number} data.judgeId - 评委ID
 * @param {String} data.role - 角色（judge/chief_judge）
 * @param {Number} data.venueId - 场地ID（普通评委必填）
 * @param {String} data.projects - 项目列表（JSON）
 * @param {Number} data.expireDays - 过期天数（默认30）
 */
export const generateInviteCode = (data) => {
  return request({
    url: '/api/martial/judgeInvite/generate',
    method: 'post',
    data
  })
}

/**
 * 批量生成邀请码
 * @param {Object} data - 批量生成参数
 * @param {Number} data.competitionId - 赛事ID
 * @param {Array} data.judgeIds - 评委ID数组
 * @param {String} data.role - 角色（默认judge）
 * @param {Number} data.expireDays - 过期天数（默认30）
 */
export const batchGenerateInviteCode = (data) => {
  return request({
    url: '/api/martial/judgeInvite/generate/batch',
    method: 'post',
    data
  })
}

/**
 * 重新生成邀请码
 * @param {Number} inviteId - 邀请ID
 */
export const regenerateInviteCode = (inviteId) => {
  return request({
    url: `/api/martial/judgeInvite/regenerate/${inviteId}`,
    method: 'put'
  })
}

/**
 * 查询评委的邀请码
 * @param {Number} competitionId - 赛事ID
 * @param {Number} judgeId - 评委ID
 */
export const getInviteByJudge = (competitionId, judgeId) => {
  return request({
    url: '/api/martial/judgeInvite/byJudge',
    method: 'get',
    params: { competitionId, judgeId }
  })
}
