import request from '@/utils/request'
import {
  add,
  update,
  confirm,
  messageSend
} from './base'

// 查询摄像头
export function getCameras (query) {
  const { pageNum: pageIndex, pageSize, ...params } = query
  return request({
    url: '/camera/list',
    method: 'GET',
    params: {
      pageIndex, pageSize,
      ...params
    }
  })
}

// 新增摄像头
export function addCamera (data) {
  return add({
    url: '/camera',
    method: 'POST',
    data
  })
}

// 编辑摄像头
export function updateCamera (data) {
  return update({
    url: '/camera',
    method: 'PUT',
    data
  })
}

// 删除摄像头
export function deleteCamera ({ id, name }) {
  return confirm(`确定删除 ${name}？`).then(() => messageSend({
    url: `/camera/${id}`,
    method: 'DELETE'
  }, '删除'))
}

// 获取摄像头人流量
export function getStatistic (params) {
  return request({
    url: `/camera/statistic`,
    method: 'GET',
    params
  })
}

// 获取摄像头当前的视频参数
export function getVideoinfo (deviceId) {
  return request({
    url: `/camera/${deviceId}/video/param`,
    method: 'GET'
  })
}

// 获取摄像头可用的视频参数
export function getAvailableParam () {
  return request({
    url: `/camera/video/availableParam`,
    method: 'GET'
  })
}

// 设置摄像头参数
export function setCamera (data) {
  const { deviceId, ...params } = data
  return update({
    url: `/camera/${deviceId}/video/param`,
    method: 'PUT',
    data: params
  })
}

// 摄像头在线状态
export function getOnline (deviceId) {
  return request({
    url: `/camera/${deviceId}/online`,
    method: 'GET'
  })
}

// 获取授权码
export function authCode (query) {
  const { deviceId } = query
  return request({
    url: `/deviceStream/${deviceId}/authCode`,
    method: 'GET'
  })
}

// 直播流详情
export function detail (stream) {
  return request({
    url: `/${stream}/detail`,
    method: 'GET'
  })
}
