import http from './http'

/**
 * 获取当前题图设置
 * @returns {Promise<{cover_path: string|null, episode_number: number|null, episode_title: string|null}>}
 */
export async function getCurrentCover() {
  const response = await http.get('/dashboard/cover')
  return response.data
}

/**
 * 上传题图（仅制片人/责编可用）
 * @param {File} file - 海报图片文件
 * @param {number} episodeNumber - 关联期次号
 * @param {string} episodeTitle - 关联期次节目名
 * @returns {Promise<{success: boolean, cover_path: string}>}
 */
export async function uploadCover(file, episodeNumber, episodeTitle) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('episode_number', String(episodeNumber))
  formData.append('episode_title', episodeTitle)
  const response = await http.post('/dashboard/cover', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
  return response.data
}

/**
 * 获取未来排播计划
 * @param {number} limit - 返回条数，默认6
 * @returns {Promise<Array<{episode_number, program_name, planned_air_date, editor_name_snapshot}>>}
 */
export async function getUpcomingSchedules(limit = 6) {
  const response = await http.get('/schedules/upcoming', { params: { limit } })
  return response.data
}