import HelperUtil from '../../utils/HelperUtil'
import DeviceControllAPI from '../../api/restApis/DeviceControllAPI'

// 静态方法
let staticMethods = {

  // 获取温度
  getDeviceTemperature: function (panelsDeviceKey) {
    return DeviceControllAPI.getDeviceTemperature(panelsDeviceKey).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 获取软件版本
  getDeviceSoftware: function (panelsDeviceKey) {
    return DeviceControllAPI.getDeviceSoftware(panelsDeviceKey).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 获取硬件版本
  getDeviceHardware: function (panelsDeviceKey) {
    return DeviceControllAPI.getDeviceHardware(panelsDeviceKey).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 获取风扇状态
  getDevcieFanstatus: function (panelsDeviceKey) {
    return DeviceControllAPI.getDevcieFanstatus(panelsDeviceKey).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 重启设备
  getRestartDevice: function (panelsDeviceKey) {
    return DeviceControllAPI.getRestartDevice(panelsDeviceKey).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function DeviceControllService (websocketService = null) {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(DeviceControllService, staticMethods)
export default DeviceControllService
