import request from '@/axios';

// ==================== f/[‹ô­¡¥ã ====================

/**
 * ô­ô°uåâ
 * @param {Number} current - SMu,Ø¤1
 * @param {Number} size - Ïuap,Ø¤10
 * @param {Object} params - åâÂp
 * @param {Number} params.competitionId - [‹ID
 * @param {String} params.updateType - ô°{‹match[µ/resulté/noticeå	
 * @param {Number} params.projectId - yîIDï		
 * @param {Number} params.venueId - :0IDï		
 */
export const getLiveUpdateList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/live-update/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * ·Öô­ô°æÅ
 * @param {Number} id - ô°ID
 */
export const getLiveUpdateDetail = (id) => {
  return request({
    url: '/api/blade-martial/live-update/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * Ñô­ô°
 * @param {Object} data - ô­ô°pn
 * @param {Number} data.competitionId - [‹ID
 * @param {String} data.title - ˜
 * @param {String} data.content - …¹Ì‡,	
 * @param {String} data.updateType - ô°{‹
 * @param {Number} data.projectId - yîIDï		
 * @param {Number} data.venueId - :0IDï		
 * @param {Array} data.images - þGURLpÄ
 * @param {Array} data.videos - Æ‘URLpÄ
 * @param {Boolean} data.isTop - /&nv
 */
export const publishLiveUpdate = (data) => {
  return request({
    url: '/api/blade-martial/live-update/publish',
    method: 'post',
    data
  })
}

/**
 * î9ô­ô°
 * @param {Object} data - ô­ô°pn
 */
export const updateLiveUpdate = (data) => {
  return request({
    url: '/api/blade-martial/live-update/update',
    method: 'post',
    data
  })
}

/**
 *  dô­ô°
 * @param {String} ids - ô°ID,*(÷”
 */
export const removeLiveUpdate = (ids) => {
  return request({
    url: '/api/blade-martial/live-update/remove',
    method: 'post',
    params: { ids }
  })
}

/**
 * bnv¶
 * @param {Number} id - ô°ID
 * @param {Boolean} isTop - /&nv
 */
export const toggleTop = (id, isTop) => {
  return request({
    url: '/api/blade-martial/live-update/toggle-top',
    method: 'post',
    data: { id, isTop }
  })
}

/**
 * 
 ô­þG
 * @param {File} file - þG‡ö
 */
export const uploadLiveImage = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/blade-martial/live-update/upload-image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 
 ô­Æ‘
 * @param {File} file - Æ‘‡ö
 * @param {Function} onProgress - 
 Û¦Þ
 */
export const uploadLiveVideo = (file, onProgress) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/blade-martial/live-update/upload-video',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    onUploadProgress: onProgress
  })
}

/**
 * yÏ
 þG
 * @param {Array} files - þG‡öpÄ
 */
export const batchUploadImages = (files) => {
  const formData = new FormData()
  files.forEach(file => {
    formData.append('files', file)
  })
  return request({
    url: '/api/blade-martial/live-update/batch-upload-images',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * ·Öô­ß¡pn
 * @param {Number} competitionId - [‹ID
 */
export const getLiveStatistics = (competitionId) => {
  return request({
    url: '/api/blade-martial/live-update/statistics',
    method: 'get',
    params: { competitionId }
  })
}

/**
 * ¹^ô­ô°
 * @param {Number} id - ô°ID
 */
export const likeLiveUpdate = (id) => {
  return request({
    url: '/api/blade-martial/live-update/like',
    method: 'post',
    data: { id }
  })
}

/**
 * Öˆ¹^
 * @param {Number} id - ô°ID
 */
export const unlikeLiveUpdate = (id) => {
  return request({
    url: '/api/blade-martial/live-update/unlike',
    method: 'post',
    data: { id }
  })
}

/**
 * ·Öíèô­ô°
 * @param {Number} competitionId - [‹ID
 * @param {Number} limit - pÏP6
 */
export const getHotLiveUpdates = (competitionId, limit = 10) => {
  return request({
    url: '/api/blade-martial/live-update/hot',
    method: 'get',
    params: { competitionId, limit }
  })
}
