import Axios from 'axios'
import {
  DEVICE_ADMQ_TOTAL, DEVICE_ADMQ, DEVICE_UPLOAD, DEVICE_DOWNLOAD, DEVICE_BOOK_DOWNLOAD, DEVICE_HISTORY_CONFIG,
  REQUEST_CONFIG, DEVICE_CONDITION_QUERY, DEVICE_DOWNLOAD_DEVICE_LOG,
  DEVICE_DISCOVER, DEVICE_PORT_CONFIG, DEVICE_TYPE_KEY, DEVICE_PORT_STATUS,
  DEVICE_INFOS, DEVICE_BATCH_ADD, DEVICE_BATCH_SEARCH, DEVICE_TYPE_ADMQ, DEVICE_QUERY,
  DEVICE_PORT_NUM, DEVICE_MODEL_ADMQ, DEVICE_ADMQ_TOTAL_PAGE, DEVICE_PORT, ORACLE_QUERY
} from '../../utils/RequestUrls'

var staticMethods = {
  /**
   * @Description  : putDataQueryAPI
   * @author       : ls
   * @date         : 2020/11/19 9:48
   * @param        :
   * @return       :
   */
  putDataQueryAPI: function (val) {
    return Axios.put(ORACLE_QUERY, val, REQUEST_CONFIG)
  },
  // 获取所有设备
  getDeviceCollection: function () {
    return Axios.get(DEVICE_ADMQ)
  },
  /**
   * @Description  : 分页查询API
   * @author       : ls
   * @date         : 2020/5/6 16:05
   * @param        :
   * @return       :
   */
  putDeviceQueryterms: function (beginItem, endItem, selectList) {
    return Axios.put(DEVICE_ADMQ_TOTAL_PAGE + '/' + beginItem + '/' + endItem + '/', selectList, REQUEST_CONFIG)
  },
  /**
   * @Description  : 查询总页数
   * @author       : ls
   * @date         : 2020/5/6 16:06
   * @param        :
   * @return       :
   */
  putDeviceCounts: function (selectList) {
    return Axios.put(DEVICE_ADMQ_TOTAL, selectList, REQUEST_CONFIG)
  },
  getDeviceTypeCollection: function () {
    return Axios.get(DEVICE_TYPE_ADMQ)
  },
  /**
   * @Description  : 获取网元型号
   * @author       : ls
   * @date         : 2020/4/26 18:33
   * @param        :
   * @return       :
   */
  getDeviceModelCollection: function () {
    return Axios.get(DEVICE_MODEL_ADMQ)
  },
  getDevicePortNum: function (deviceKey) {
    return Axios.put(DEVICE_PORT_NUM, deviceKey, REQUEST_CONFIG)
  },

  // 上传设备
  postUploadDevice: function (fileFormData) {
    return Axios.post(DEVICE_UPLOAD + '/1', fileFormData, {headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'application/json'
    }})
  },

  // 下载设备
  putDownloadDevice: function (conditionSet) {
    return Axios.put(DEVICE_DOWNLOAD, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  /**
   * @Description  : 网元台账
   * @author       : ls
   * @date         : 2020/6/9 9:56
   * @param        :
   * @return       :
   */
  putDownloadDeviceBook: function (conditionSet) {
    return Axios.put(DEVICE_BOOK_DOWNLOAD, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  // 查询某一设备的所有历史配置
  putDeviceHistoryConfig: function (conditionSet) {
    return Axios.put(DEVICE_HISTORY_CONFIG, conditionSet, REQUEST_CONFIG)
  },

  // 手动获取设备信息
  getDeviceInfoByManual: function (ipAddress) {
    return Axios.put(DEVICE_ADMQ + ipAddress, {}, REQUEST_CONFIG)
  },

  // 设备的条件查询
  putConditionQueryDevice: function (conditionSet) {
    return Axios.put(DEVICE_CONDITION_QUERY, conditionSet, REQUEST_CONFIG)
  },
  putQueryDevice: function (conditionSet) {
    return Axios.put(DEVICE_QUERY, conditionSet, REQUEST_CONFIG)
  },

  // 设备的修改
  putModifyDevice: function (device) {
    return Axios.put(DEVICE_ADMQ, device, REQUEST_CONFIG)
  },

  // 设备的新建、复制
  postAddDevice: function (device) {
    return Axios.post(DEVICE_ADMQ, device, REQUEST_CONFIG)
  },

  // 设备的批量删除
  batchDeleteDevice: function (deviceKeyList) {
    return Axios.delete(DEVICE_ADMQ, {
      data: deviceKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    })
  },

  // 下载设备日志
  putDownloadDeviceLog: function (deviceKey) {
    return Axios.put(DEVICE_DOWNLOAD_DEVICE_LOG + deviceKey, {}, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  // 传统设备发现
  putDiscoverTraditionalDevices: function (ipGroup) {
    return Axios.put(DEVICE_DISCOVER, ipGroup, REQUEST_CONFIG)
  },

  // 获取设备型号Key
  putDeviceTypeKey: function (conditionSet) {
    return Axios.put(DEVICE_TYPE_KEY, conditionSet, REQUEST_CONFIG)
  },

  /**
   * @Description  : 获取端口状态
   * @author       : ls
   * @date         : 2020/11/2 17:21
   * @param        :
   * @return       :
   */
  getDevicePortStatus: function (panelsDeviceKey) {
    return Axios.put(DEVICE_PORT_STATUS, panelsDeviceKey, REQUEST_CONFIG)
  },
  /**
   * @Description  : 获取端口状态
   * @author       : ls
   * @date         : 2020/11/4 17:06
   * @param        :
   * @return       :
   */
  getDevicePortAPI: function (deviceKey) {
    return Axios.put(DEVICE_PORT, deviceKey, REQUEST_CONFIG)
  },

  // 获取设备端口配置
  putDevicePortConfig: function (conditionSet) {
    return Axios.put(DEVICE_PORT_CONFIG, conditionSet, REQUEST_CONFIG)
  },

  // 获取指定设备信息
  getDeviceInfo: function (ipAddress) {
    return Axios.get(DEVICE_INFO + ipAddress)
  },

  postDeviceInfo: function (deviceInfo) {
    // return Axios.post(DEVICE_INFO, deviceInfo, REQUEST_CONFIG)
    return Axios.get(DEVICE_INFOS + '/' + deviceInfo, REQUEST_CONFIG)
  },

  // 获取设备端口光功率
  putDeviceLuminousPower: function (portName, device) {
    return Axios.put(DEVICE_ADMQ + portName, device, REQUEST_CONFIG)
  },

  // 批量添加设备
  putBatchAddDevice: function (deviceList) {
    return Axios.put(DEVICE_BATCH_ADD, deviceList, REQUEST_CONFIG)
  },

  // ls 设备发现
  postSearchDevice1: function (searchCondition) {
    return Axios.get(DEVICE_BATCH_SEARCH, searchCondition, REQUEST_CONFIG)
  },
  postSearchDevice: function () {
    return Axios.get(DEVICE_BATCH_SEARCH, REQUEST_CONFIG)
  }

}

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