import Axios from 'axios'

import {
  LINK_ADMQ,
  REQUEST_CONFIG,
  LINK_CONDITION_QUERY,
  LINK_DOWNLOAD,
  LINK_IMPORT,
  LINK_ADMQ_TOTAL_PAGE, LINK_ADMQ_TOTAL
} from '../../utils/RequestUrls'

var staticMethods = {
  // 获取所有链路
  getLinkCollection: function () {
    return Axios.get(LINK_ADMQ)
  },
  // 删除链路
  deleteLink: function (LinkKeyList) {
    return Axios.delete(LINK_ADMQ, {
      data: LinkKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    })
  },
  // 增加链路
  postLinkAdd: function (addLink) {
    return Axios.post(LINK_ADMQ, addLink, REQUEST_CONFIG)
  },
  // 修改链路
  putModifyLink: function (link) {
    return Axios.put(LINK_ADMQ, link, REQUEST_CONFIG)
  },
  // 条件查询链路
  putConditionQueryLink: function (conditionSet) {
    return Axios.put(LINK_CONDITION_QUERY, conditionSet, REQUEST_CONFIG)
  },
  /**
   * @description   : 导入
   * @author        : ls
   * @date          : 2020/6/23 22:01
   * @param         :
   * @return        :
   **/
  postUploadLink: function (fileFormData) {
    return Axios.post(LINK_IMPORT + '/1', fileFormData, {headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'application/json'
    }})
  },
  /**
   * @description   : 导出
   * @author        : ls
   * @date          : 2020/6/23 22:00
   * @param         :
   * @return        :
   **/
  putDownloadLink: function (conditionSet) {
    return Axios.put(LINK_DOWNLOAD, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  /**
   * @Description  : 分页查询
   * @author       : ls
   * @date         : 2020/6/24 10:00
   * @param        :
   * @return       :
   */
  putLinkQueryterms: function (beginItem, endItem, selectList) {
    return Axios.put(LINK_ADMQ_TOTAL_PAGE + '/' + beginItem + '/' + endItem + '/', selectList, REQUEST_CONFIG)
  },
  /**
   * @Description  : 查询总数
   * @author       : ls
   * @date         : 2020/6/24 10:00
   * @param        :
   * @return       :
   */
  putLinkCounts: function (selectList) {
    return Axios.put(LINK_ADMQ_TOTAL, selectList, REQUEST_CONFIG)
  }
}

function LinkAPI (websocketService = null) {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(LinkAPI, staticMethods)
export default LinkAPI
