import Axios from 'axios'

import {
  TOPOLOGICAL_DOWNLOAD,
  TOPOLOGICAL_UPLOAD,
  TOPOLOGICAL_QUERY,
  TOPOLOGICAL_ADMQ,
  TOPOLOGICAL_ATV,
  TOPOLOGICAL_DATV,
  REQUEST_CONFIG,
} from "../../../utils/RequestUrls";

var staticMethods = {
  // 获取所有动态拓扑
  getTopoCollection: function() {
    return Axios.get(TOPOLOGICAL_ADMQ)
  },
  // 查询拓扑
  queryTopoCollection: function(conditionSet) {
    return Axios.put(TOPOLOGICAL_QUERY,conditionSet,REQUEST_CONFIG)
  },
  // 导出动态拓扑
  putDownloadTopoDynamic: function (conditionSet) {
    return Axios.put(TOPOLOGICAL_DOWNLOAD, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  // 删除拓扑
  deleteDeleteTopological: function (topoKeyList) {
    return Axios.delete(TOPOLOGICAL_ADMQ, {
      data: topoKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    });
  },

  putEnableTopological: function (enableString) {
    return Axios.put(TOPOLOGICAL_ATV,enableString,REQUEST_CONFIG);
  },

  putDisableTopological: function (disableString) {
    return Axios.put(TOPOLOGICAL_DATV,disableString,REQUEST_CONFIG);
  },

  // 动态拓扑文件上传
  postUploadTopoDynamic: function (fileFormData) {
    return Axios.post(TOPOLOGICAL_UPLOAD,fileFormData,{headers: {
        'Content-Type': 'multipart/form-data',
        'Accept': 'application/json'
      }});
  }
};

function TopologicalDynamicAPI (websocketService = null) {

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