import Axios from 'axios'

import {REQUEST_CONFIG, TOP_PERFORM_COUNT, PERFORMANCE_COUNT, PERFORMANCE_QUERY, PERFORMANCE_DOWNLOAD_CSV, PERFORMANCE_DOWNLOAD, HISTORY_DATA} from '../../utils/RequestUrls'

var staticMethods = {

  // 性能数据按条件查询：总条数
  putPerformanceCounts: function (selectList) {
    return Axios.put(PERFORMANCE_COUNT, selectList, REQUEST_CONFIG)
  },
  /**
   * @Description  : topn性能查询总数
   * @author       : ls
   * @date         : 2020/6/29 9:52
   * @param        :
   * @return       :
   */
  putTopNPerformanceCounts: function (num, selectList) {
    return Axios.put(TOP_PERFORM_COUNT + num, selectList, REQUEST_CONFIG)
  },

  // 性能数据按条件查询：分页性能
  putPerformanceQueryterms: function (beginItem, endItem, selectList) {
    return Axios.put(PERFORMANCE_QUERY + beginItem + '/' + endItem + '/', selectList, REQUEST_CONFIG)
  },
  /**
   * @Description  : top查询
   * @author       : ls
   * @date         : 2020/6/29 10:45
   * @param        :
   * @return       :
   */
  putPerformanceQuery: function (num, selectList) {
    return Axios.put(PERFORMANCE_QUERY + num, selectList, REQUEST_CONFIG)
  },
  // 导出excel
  putDownloadPerformance: function (selectList) {
    return Axios.put(PERFORMANCE_DOWNLOAD, selectList, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  putDownloadPerformanceCsv: function (selectList) {
    return Axios.put(PERFORMANCE_DOWNLOAD_CSV, selectList, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  putQueryPerformTaskData: function (val) {
    return Axios.put(HISTORY_DATA, val, REQUEST_CONFIG)
  }
}

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