import request from '@/utils/request'
import { type } from 'os'

/**
 * 控制设备
 * @param {*} data
 * @returns
 */
export function invoke (data) {
  return request({
    url: '/manager/dev/control/invokeIotDevYunTaiXgFunction',
    method: 'post',
    data
  })
}
/**
 * 指定设备姿态
 * @param {*} data
 */
export function invokeControl (data) {
  return request({
    url: '/manager/dev/control/invokeIotDevCtrlCommandFunctionForXg',
    method: 'post',
    data
  })
}
/**
 * 获取设备姿态
 * @param {*}} deviceCode
 */
export function getDevicePosture (deviceCode) {
  return request({
    url: '/manager/dev/device/getDevStatusFromCacheByKey/' + deviceCode,
    method: 'get'
  })
}


/**
 * 获取播放地址
 * @param {*} deviceCode
 * @param {*} channelCode
 */
export function getMediaUrl (deviceCode, channelCode, noAlert) {
  return request({
    noAlert,
    url: "/patrol/video/realtime",
    methods: 'get',
    params: {
      patroldeviceCode: deviceCode,
      channelCode
    }
  })
}

/**
 * 云台控制
 * @param {*} params
 */
export function controlPanTilt (params) {
  return request({
    url: "/patrol/videotape/ptz",
    methods: 'get',
    params
  })
}


/**
 * 刷新联动数据
 */
export function refreshUnionTaskData () {
  return request({
    url: "/patrol/linkage/popup",
    methods: 'get'
  })
}

/**
 * 获取通道列表
 */
export function getDeviceChannelList (deviceCode) {
  return request({
    url: "/basedata/eqpbook/channel/getChannelByEqpbookCode",
    methods: 'get',
    params: {
      patroldeviceCode: deviceCode
    }
  })
}


/**
 * 根据任务获取巡视设备及视频通道树
 */
 export function taskByEqbookchannel (taskCode) {
  return request({
    url: "/patrol/task/taskByEqbookchannel",
    methods: 'get',
    params: {
      taskCode: taskCode
    }
  })
}


/**
 * 控制机器人
 */
export function controlRobot (deviceCode, type, command, value = null) {
  const data = {
    Code: deviceCode,
    Type: type,
    Command: command
  }

  if (value) {
    data.Items = [
      {
        Value: value
      }
    ]
  }
  return request({
    url: "/patrol/client/send",
    method: 'post',
    data
  })
}
/**
 * 控制机器人带验证
 */
export function controlRobotWithVerifition (deviceCode, type, command, value = null) {
  const data = {
    Code: deviceCode,
    Type: type,
    Command: command
  }

  if (value) {
    data.Items = [
      {
        Value: value
      }
    ]
  }
  return request({
    url: "/patrol/client/sendImportantMsg",
    method: 'post',
    data
  })
}

/**
 * 心跳
 * @param {*} streamId
 * @returns
 */
export function recordHeartbeat (streamId) {
  return request({
    url: '/patrol/videotape/heartbeat',
    method: 'get',
    params: {
      streamId: streamId
    }
  })
}



/**
 * 开始录像
 * @param {*} streamId
 * @param {*} action   0  /  1
 * @returns
 */
export function record (streamId, action = 0) {
  return request({
    url: '/patrol/videotape/record',
    method: 'get',
    params: {
      streamid: streamId,
      action
    }
  })
}

/**
 * 获取服务器信息
 * @returns
 */
export function getServiceDeviceInfo () {
  return request({
    url: '/patrol/client/systemInfo',
    method: 'get',
    params: {}
  })
}


/**
 * 获取服务器信息
 * @returns
 */
export function getTemperatureValue (shapeInfo, type, imgUrl) {
  return request({
    url: '/patrol/infrared',
    method: 'get',
    params: {
      imgUrl,
      coordinate: shapeInfo,
      type
    }
  })
}

/**
 * 获取nvr信息
 * @returns
 */
export function getNvrInfoList () {
  return request({
    url: '/basedata/nvr/selectNewInfo',
    method: 'post',
    data: {}
  })
}


/**
 * 获取nvr信息在线状态
 * @returns
 */
 export function getAllNvrDeviceOlineStatusDataByCache () {
  return request({
    url: '/basedata/montdata/querydata/getAllNvrDeviceOlineStatusDataByCache',
    method: 'get',
    data: {}
  })
}

/**
 * 修改声纹
 * @returns
 */
export function changeVoiceState (deviceId, bflag) {
  return request({
    url: '/voicedata/swOn',
    method: 'get',
    params: {
      devId: deviceId,
      flag: bflag ? 'ON' : 'OFF'
    }
  })
}
