import http from '@/utils/http'

/* 分页查询 */
export function getVideoPage(params: {
  pageNo: number
  pageSize: number
  projectId: string
  turbineId?: string
}) {
  return http.get('/video-monitor/page',  params )
}

/* 单文件上传 */
export function uploadSingleVideo(
  projectId: string,
  turbineId: string,
  type: string,
  file: File
) {
  const fd = new FormData()
  fd.append('file', file)
  return http.post(
    `/video-monitor/${projectId}/upload?turbineId=${turbineId}&type=${type}`,
    fd,
    { headers: { 'Content-Type': 'multipart/form-data' } }
  )
}

/* 批量上传 */
export function uploadBatchVideo(
  projectId: string,
  turbineId: string,
  type: string,
  files: File[]
) {
  const fd = new FormData()
  files.forEach(f => fd.append('files', f))
  return http.post(
    `/video-monitor/${projectId}/upload-batch?turbineId=${turbineId}&type=${type}`,
    fd,
    { headers: { 'Content-Type': 'multipart/form-data' } }
  )
}

/* 删除 */
export function deleteVideo(videoId: string) {
  return http.del(`/video-monitor/${videoId}`)
}

/* 下载 */
export function downloadVideo(videoId: string) {
  return http
    .get(`/video-monitor/download/${videoId}`, { responseType: 'blob' })
    .then(blob => URL.createObjectURL(blob))
}