import Axios from 'axios'

import {LOCATION_ADMQ,LOCATION_QUERY,LOCATION_UPLOAD,LOCATION_DOWNLOAD,REQUEST_CONFIG} from "../../utils/RequestUrls";

var staticMethods = {
  // 获取所有机房
  getLocationCollection: function(){
    return Axios.get(LOCATION_ADMQ);
  },

  // 添加机房
  postAddLocation: function (location) {
    return Axios.post(LOCATION_ADMQ,location,REQUEST_CONFIG);
  },

  // 删除机房
  deleteDeleteLocation: function (locationKeyList) {
    return Axios.delete(LOCATION_ADMQ,{
      data:locationKeyList,
      headers:{'Content-Type':'application/json','Encoding':'utf-8'}
    });
  },

  // 修改机房
  putModifyLocation: function (location) {
    return Axios.put(LOCATION_ADMQ,location,REQUEST_CONFIG);
  },

  // 条件查询机房
  putConditionQueryLocation: function (conditionSet) {
    return Axios.put(LOCATION_QUERY,conditionSet,REQUEST_CONFIG);
  },

  // 机房文件下载
  putDownloadLocation: function (conditionSet) {
    return Axios.put(LOCATION_DOWNLOAD,conditionSet,{
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    });
  },

  // 机房文件上传
  postUploadLocation: function (fileFormData) {
    return Axios.post(LOCATION_UPLOAD + '/1',fileFormData,{headers: {
        'Content-Type': 'multipart/form-data',
        'Accept': 'application/json'
      }});
  }

};

function LocationAPI (websocketService = null) {

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