import request from '@/utils/request'

// 查询歌单列表
export function listPlaylist(query) {
  return request({
    url: '/back/playlist/list',
    method: 'get',
    params: query
  })
}

// 查询歌单详细
export function getPlaylist(id) {
  return request({
    url: '/back/playlist/' + id,
    method: 'get'
  })
}

// 新增歌单
export function addPlaylist(data) {
  const formData = new FormData()
  formData.append('musicName', data.musicName)
  formData.append('producer', data.producer)
  formData.append('fileType', data.fileType)
  formData.append('permission', data.permission)
  formData.append('category', data.category)
  formData.append('tags', JSON.stringify(data.tags))
  formData.append('status', data.status)
  formData.append('audioType', data.audioType)
  if (data.file) {
    formData.append('file', data.file)
  }
  return request({
    url: '/back/playlist/add',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 修改歌单
export function updatePlaylist(data) {
  const formData = new FormData()
  formData.append('id', data.id)
  formData.append('musicName', data.musicName)
  formData.append('producer', data.producer)
  formData.append('fileType', data.fileType)
  formData.append('permission', data.permission)
  formData.append('category', data.category)
  formData.append('tags', JSON.stringify(data.tags))
  formData.append('status', data.status)
  formData.append('audioType', data.audioType)
  if (data.file) {
    formData.append('file', data.file)
  }
  return request({
    url: '/back/playlist/update',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除歌单
export function delPlaylist(id) {
  return request({
    url: '/back/playlist/' + id,
    method: 'delete'
  })
} 