import Axios from 'axios'
import {
  REQUEST_CONFIG, PORTLIST_ADMQ, PORTLIST_CONDITION_QUERY, PORTLIST_UPLOAD,
  PORTLIST_DOWNLOAD
} from "../../utils/RequestUrls";

var staticMethods = {
  // 条件查询接入业务
  putConditionQueryPortList: function (conditionSet) {
    return Axios.put(PORTLIST_CONDITION_QUERY,conditionSet,REQUEST_CONFIG);
  },

  // 删除接入业务
  deleteDeletePortList: function (portKeyList) {
    return Axios.delete(PORTLIST_ADMQ,{
      data:portKeyList,
      headers:{'Content-Type':'application/json','Encoding':'utf-8'}
    });
  },

  // 获取全部端口信息
  getAllPortList: function () {
    return Axios.get(PORTLIST_ADMQ);
  },

  // 导入端口文件
  postUploadPortListFile: function (fileFormData) {
    return Axios.post(PORTLIST_UPLOAD + '/1',fileFormData,{headers: {
        'Content-Type': 'multipart/form-data',
        'Accept': 'application/json'
      }});
  },

  // 下载端口文件
  putDownloadPortListFile: function (conditionSet) {
    return Axios.put(PORTLIST_DOWNLOAD,conditionSet,{
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    });
  },

  // 创建端口
  postAddPort: function (port) {
    return Axios.post(PORTLIST_ADMQ,port,REQUEST_CONFIG);
  },

  // 修改端口
  putModifyPort: function (port) {
    return Axios.put(PORTLIST_ADMQ,port,REQUEST_CONFIG);
  }
};

function PortListAPI (websocketService = null) {

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