import HelperUtil from '../../../utils/HelperUtil'
import {TOPO_DYNAMIC_KEY,TOPOLOGICAL_DOWNLOAD_FILE_NAME} from "../../../utils/constantCollection";
import TopologicalDynamicAPI from "../../../api/restApis/BusinessAPI/TopologicalDynamicAPI";
import NetworkPhysicsAPI from "../../../api/restApis/BusinessAPI/NetworkPhysicsAPI";

// 静态方法
let staticMethods = {
  // 获取所有拓扑
  getAllTopologicalCollection: function () {
    return TopologicalDynamicAPI.getTopoCollection().then(result => {
      if (result.data.result) {
      return HelperUtil.arrayToObject(result.data.returnValue, TOPO_DYNAMIC_KEY)
    } else {
      return HelperUtil.returnPromiseRejectObj(result)
    }
  })
  },

  // 条件查询
  conditionQueryTopo: function (conditionSet) {
    return TopologicalDynamicAPI.queryTopoCollection(conditionSet).then(result => {
      if (result.data.result) {
      return HelperUtil.arrayToObject(result.data.returnValue, TOPO_DYNAMIC_KEY)
    } else {
      return HelperUtil.returnPromiseRejectObj(result)
    }
  })
  },

  // 导出动态拓扑
  downloadTopoDynamic: function (conditionSet) {
    return TopologicalDynamicAPI.putDownloadTopoDynamic(conditionSet).then(result => {
      return HelperUtil.downFile(result, TOPOLOGICAL_DOWNLOAD_FILE_NAME);
  })
  },

  // 删除拓扑
  deleteTopologicalDynamic: function (topoKeyList) {
    return TopologicalDynamicAPI.deleteDeleteTopological(topoKeyList).then(result => {
      if (result.data.result) {
    }else{
      return HelperUtil.returnPromiseRejectObj(result);
    }
  });
  },

  //启用
  enableTopologicalDynamic: function (enableString) {
    return TopologicalDynamicAPI.putEnableTopological(enableString).then(result => {
      if (result.data.result) {
    }else{
      return HelperUtil.returnPromiseRejectObj(result);
    }
  });
  },

  //禁用
  disableTopologicalDynamic: function (disableString) {
    return TopologicalDynamicAPI.putDisableTopological(disableString).then(result => {
      if (result.data.result) {
    }else{
      return HelperUtil.returnPromiseRejectObj(result);
    }
  });
  },
  // 导入动态拓扑
  uploadTopoDynamic: function (fileFormData) {
    return TopologicalDynamicAPI.postUploadTopoDynamic(fileFormData).then(result => {
      if (result.data.result) {
    }else{
      return HelperUtil.returnPromiseRejectObj(result);
    }
  });
  }
};

function TopologicalDynamicService (websocketService = null) {

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