import http from '@/utils/request'

// 获取列表
export function getList (params) {
  const entries = Object.entries(params).filter(arr => arr[1]).map(arr => {
    return `${arr[0]}=${arr[1]}`
  })
  const str = entries.join('&')
  return http.get(`/adv/?${str}`)
}
// 激活/禁用
export function active (id, value) {
  return http.post(`/adv/${id}/active`, { active: value })
}
// 删除
export function deleteItem (id) {
  return http.delete(`/adv/${id}`)
}
// 添加
export function addItem (params) {
  return http.post('/adv', params)
}
// 详情
export function getDetail (id) {
  return http.get(`/adv/${id}`)
}
// 编辑
export function editItem (id, params) {
  return http.put(`/adv/${id}`, params)
}
/* 广告位管理 */
// 获取广告位列表
export function getAdvPosition (params) {
  const entries = Object.entries(params).filter(arr => arr[1]).map(arr => {
    return `${arr[0]}=${arr[1]}`
  })
  const str = entries.join('&')
  return http.get(`/advposition/?${str}`)
}
// 添加广告位
export function addAdvPosition (params) {
  return http.post('/advposition', params)
}
// 广告位详情
export function getAdvPositionDetail (id) {
  return http.get(`/advposition/${id}`)
}
// 编辑广告位
export function editAdvPosition (id, params) {
  return http.put(`/advposition/${id}`, params)
}
// 删除广告位
export function deleteAdvPosition (id) {
  return http.delete(`/advposition/${id}`)
}
// 激活/禁用广告位
export function activeAdvPosition (id, value) {
  return http.post(`/advposition/${id}/active`, { active: value })
}
/* 版本管理 */
// 版本预览
export function versionPreview () {
  return http.get(`/advversion/preview`)
}
// 创建版本
export function addVersion (params) {
  return http.post(`/advversion`, params)
}
// 版本列表
export function getVersionList (params) {
  return http.get(`/advversion/?pageNum=${params.pageNum}&status=${params.status}`)
}
// 激活/禁用
export function activeVersion (id, value) {
  return http.post(`/advversion/${id}/active`, { active: value })
}
// 版本详情
export function getVersionDetail (id) {
  return http.get(`/advversion/${id}`)
}
// 发布字幕
export function publishAdv (version, users) {
  return http.post(`/realtimecmd`, {
    param: {
      type: 'ADVPUBLISH',
      version: version
    },
    users: users
  })
}
