import Axios from 'axios'
import {
  CABINET_ADMQ,
  CABINET_QUERY,
  CABINET_UPLOAD,
  CABINET_DOWNLOAD,
  REQUEST_CONFIG,
  FIRMWARE,
  FIRMWARE_QUERY,
  DOWNLOAD_CONFIG_TO_LOCAL_FIRMWARE,
  FIRMWARE_ADMQ,
  UPDATE_FIRMWARE_TO_DEVICE,
  RECOVER_FIRMWARE_TO_DEVICE,
  FIRMWARE_UPLOAD, CONFIG_FILE_UPLOAD_LOCAL, DOWNLOAD_CONFIG_TO_DEVICE,
} from "../../utils/RequestUrls";

var staticMethods = {
  getFirmWareCollection: function () {
    return Axios.get(FIRMWARE);
  },

  // 固件上传
  postUploadLocalFirmWare: function (fileName, deviceType, fileFormData) {
    // alert(FIRMWARE_UPLOAD + fileName + '/' + deviceType)
    return Axios.post(FIRMWARE_UPLOAD + fileName + '/' + deviceType, fileFormData, {
      headers: {
        'Content-Type': 'multipart/form-data',
        'Accept': 'application/json'
      }
    })
  },

  // 下载固件
  putDownloadFirmWare: function (firmWareKey, selectList) {
    return Axios.put(DOWNLOAD_CONFIG_TO_LOCAL_FIRMWARE + firmWareKey, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  // 更新固件
  updateFirmWare: function (firmwareKey, deviceKeyList) {
    // return Axios.put(UPDATE_FIRMWARE_TO_DEVICE + firmwareKey + '/' + deviceKeyList, REQUEST_CONFIG)
    return Axios.put(UPDATE_FIRMWARE_TO_DEVICE + firmwareKey, deviceKeyList, REQUEST_CONFIG)
  },

  // 回退固件
  recoverFirmWare: function (deviceKeyList) {
    return Axios.get(RECOVER_FIRMWARE_TO_DEVICE + deviceKeyList, REQUEST_CONFIG)
  },

  // 删除固件
  deleteBatchFirmWare: function (deleteFirmWareKeyList){
    return Axios.delete(FIRMWARE_ADMQ, {
      data: deleteFirmWareKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    })
  },

  // 条件查询固件
  putConditionQueryFirmWare: function (conditionSet) {
    return Axios.put(FIRMWARE_QUERY, conditionSet, REQUEST_CONFIG);
  },

  // 添加机架
  postAddCabinet: function (cabinet) {
    return Axios.post(CABINET_ADMQ,cabinet,REQUEST_CONFIG);
  },

  // 删除机架
  deleteDeleteCabinet: function (cabinetKeyList) {
    return Axios.delete(CABINET_ADMQ,{
      data:cabinetKeyList,
      headers:{'Content-Type':'application/json','Encoding':'utf-8'}
    });
  },

  // 修改机架
  putModifyCabinet: function (cabinet) {
    return Axios.put(CABINET_ADMQ,cabinet,REQUEST_CONFIG);
  },

  // 条件查询机架
  putConditionQueryCabinet: function (conditionSet) {
    return Axios.put(CABINET_QUERY,conditionSet,REQUEST_CONFIG);
  },

  // 机架文件下载
  putDownloadCabinet: function (conditionSet) {
    return Axios.put(CABINET_DOWNLOAD,conditionSet,{
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    });
  },

  // 机架文件上传
  postUploadCabinet: function (fileFormData) {
    return Axios.post(CABINET_UPLOAD,fileFormData,{headers: {
        'Content-Type': 'multipart/form-data',
        'Accept': 'application/json'
      }});
  }

};

function CabinetAPI (websocketService = null) {

  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(CabinetAPI, staticMethods);
export default CabinetAPI
