import HelperUtil from '../../utils/HelperUtil'
import NetworkPhysicsAPI from "../../api/restApis/BusinessAPI/NetworkPhysicsAPI";
import {NODE_NAME,NETWORK_PHYSICS_LINK_FILE_NAME} from "../../utils/constantCollection";

// 静态方法
let staticMethods = {
  // 获取所有网络物理连接
  getAllNetPhyLinkCollection: function(){
    return NetworkPhysicsAPI.getNetPhyLinkCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue,NODE_NAME);
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 添加网络物理连接
  addNetPhyLink: function (netPhy) {
    return NetworkPhysicsAPI.postAddNetPhyLink(netPhy).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 删除网络物理连接
  deleteNetPhyLink: function (netPhyList) {
    return NetworkPhysicsAPI.deleteDeleteNetPhyLink(netPhyList).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 修改机房
  modifyNetPhyLink: function (netPhy) {
    return NetworkPhysicsAPI.putModifyNetPhyLink(netPhy).then(result => {
      if (result.data.result) {
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 条件查询机房
  conditionQueryNetPhyLink: function (conditionSet) {
    return NetworkPhysicsAPI.putConditionQueryNetPhyLink(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue,NODE_NAME);
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  // 导出机房
  downloadNetPhyLink: function (conditionSet) {
    return NetworkPhysicsAPI.putDownloadNetPhyLink(conditionSet).then(result => {
      return HelperUtil.downFile(result,NETWORK_PHYSICS_LINK_FILE_NAME);
    });
  },

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

function NetworkPhysicsService (websocketService = null) {

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