import request from '@/axios';

// ==================== 活动日程管理接口 ====================

/**
 * 活动日程分页查询
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 * @param {Number} params.competitionId - 赛事ID
 * @param {String} params.activityType - 活动类型(可选)
 * @param {String} params.activityName - 活动名称(可选)
 * @param {String} params.startDate - 开始日期(可选)
 * @param {String} params.endDate - 结束日期(可选)
 */
export const getActivityScheduleList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/activity-schedule/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取活动日程详情
 * @param {Number} id - 活动ID
 */
export const getActivityScheduleDetail = (id) => {
  return request({
    url: '/api/blade-martial/activity-schedule/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 添加活动日程
 * @param {Object} data - 活动数据
 * @param {Number} data.competitionId - 赛事ID
 * @param {String} data.activityType - 活动类型(opening_ceremony/closing_ceremony/competition/training/meeting/other)
 * @param {String} data.activityName - 活动名称
 * @param {String} data.description - 活动描述
 * @param {String} data.startTime - 开始时间
 * @param {String} data.endTime - 结束时间
 * @param {String} data.location - 活动地点
 * @param {Number} data.venueId - 场地ID(可选)
 * @param {String} data.organizer - 组织者
 * @param {String} data.participants - 参与人员(可选)
 * @param {String} data.remarks - 备注(可选)
 */
export const addActivity = (data) => {
  return request({
    url: '/api/blade-martial/activity-schedule/add',
    method: 'post',
    data
  })
}

/**
 * 修改活动日程
 * @param {Object} data - 活动数据
 */
export const updateActivity = (data) => {
  return request({
    url: '/api/blade-martial/activity-schedule/update',
    method: 'post',
    data
  })
}

/**
 * 删除活动日程
 * @param {String} ids - 活动ID,多个用逗号分隔
 */
export const removeActivity = (ids) => {
  return request({
    url: '/api/blade-martial/activity-schedule/remove',
    method: 'post',
    params: { ids }
  })
}

/**
 * 获取日历视图数据
 * @param {Number} competitionId - 赛事ID
 * @param {String} month - 月份(格式: YYYY-MM)
 */
export const getActivityCalendar = (competitionId, month) => {
  return request({
    url: '/api/blade-martial/activity-schedule/calendar',
    method: 'get',
    params: { competitionId, month }
  })
}

/**
 * 检查活动时间冲突
 * @param {Object} data - 活动数据
 * @param {Number} data.competitionId - 赛事ID
 * @param {String} data.startTime - 开始时间
 * @param {String} data.endTime - 结束时间
 * @param {Number} data.venueId - 场地ID(可选)
 * @param {Number} data.excludeId - 排除的活动ID(编辑时使用)
 */
export const checkActivityConflict = (data) => {
  return request({
    url: '/api/blade-martial/activity-schedule/check-conflict',
    method: 'post',
    data
  })
}

/**
 * 复制活动
 * @param {Object} data - 复制数据
 * @param {Number} data.sourceId - 源活动ID
 * @param {String} data.newStartTime - 新开始时间
 * @param {String} data.newEndTime - 新结束时间
 */
export const copyActivity = (data) => {
  return request({
    url: '/api/blade-martial/activity-schedule/copy',
    method: 'post',
    data
  })
}

/**
 * 按日期查询活动
 * @param {Number} competitionId - 赛事ID
 * @param {String} date - 日期(格式: YYYY-MM-DD)
 */
export const getActivitiesByDate = (competitionId, date) => {
  return request({
    url: '/api/blade-martial/activity-schedule/by-date',
    method: 'get',
    params: { competitionId, date }
  })
}

/**
 * 获取活动统计
 * @param {Number} competitionId - 赛事ID
 */
export const getActivityStatistics = (competitionId) => {
  return request({
    url: '/api/blade-martial/activity-schedule/statistics',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * 按类型统计活动
 * @param {Number} competitionId - 赛事ID
 */
export const getActivityByType = (competitionId) => {
  return request({
    url: '/api/blade-martial/activity-schedule/statistics-by-type',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * 导出活动日程
 * @param {Object} params - 导出参数
 */
export const exportActivitySchedule = (params) => {
  return request({
    url: '/api/blade-martial/activity-schedule/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

/**
 * 导入活动日程
 * @param {File} file - Excel文件
 * @param {Number} competitionId - 赛事ID
 */
export const importActivitySchedule = (file, competitionId) => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('competitionId', competitionId)
  return request({
    url: '/api/blade-martial/activity-schedule/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 批量添加活动
 * @param {Array} data - 活动数据数组
 */
export const batchAddActivities = (data) => {
  return request({
    url: '/api/blade-martial/activity-schedule/batch-add',
    method: 'post',
    data
  })
}
