
// 静态方法
import HelperUtil from "../../utils/HelperUtil";
import {CABINET_KEY, LOCATION_KEY,CABINET_DOWNLOAD_FILE_NAME} from "../../utils/constantCollection";
import CabinetAPI from "../../api/restApis/CabinetAPI";
import LocationAPI from "../../api/restApis/LocationAPI";

let staticMethods = {
  // 获取所有机架
  getAllCabinetCollection: function(){
    return CabinetAPI.getCabinetCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue,CABINET_KEY);
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 添加机架
  addCabinet: function (cabinet) {
    return CabinetAPI.postAddCabinet(cabinet).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 删除机房
  deleteCabinets: function (cabinetKeyList) {
    return CabinetAPI.deleteDeleteCabinet(cabinetKeyList).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 修改机架
  modifyCabinet: function (cabinet) {
    return CabinetAPI.putModifyCabinet(cabinet).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 条件查询机架
  conditionQueryCabinet: function (conditionSet) {
    return CabinetAPI.putConditionQueryCabinet(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue,CABINET_KEY);
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 导出机架
  downloadCabinet: function (conditionSet) {
    return CabinetAPI.putDownloadCabinet(conditionSet).then(result => {
      return HelperUtil.downFile(result,CABINET_DOWNLOAD_FILE_NAME);
    });
  },

  // 导入机房
  uploadCabinet: function (fileFormData) {
    return CabinetAPI.postUploadCabinet(fileFormData).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  }
};

function CabinetService (websocketService = null) {

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