import Axios from 'axios'
import {
  ALARM_PAGING_QUERY,
  ALARM_QUERY_DOWNLOAD_EXCEL,
  ALARM_QUERY_DOWNLOAD_CSV,
  ALARMCFG_UPDATE,
  ALARMCFGLIST_ADMQ, ALARMCOUNTS_GET,
  ALARMLEVEL_UPDATE, ALARMSTATISTIC_QUERY,
  ALARMTYPELIST_ADMQ,
  ALARMREPORT_QUERY,
  REQUEST_CONFIG,
  REPORT_QUERY
} from '../../utils/RequestUrls'

var staticMethods = {
  // 获取告警列表 cxf/nms/alarm/typelist
  getAlarmTypeList: function () {
    return Axios.get(ALARMTYPELIST_ADMQ)
  },

  // 获取告警配置 cxf/nms/alarmconfig/
  getAllAlarmCfgList: function () {
    return Axios.get(ALARMCFGLIST_ADMQ)
  },

  // 告警数据按条件查询：总条数cxf/nms/alarm/totalcounts/
  getTotalCounts: function (selectList) {
    return Axios.put(ALARMCOUNTS_GET, selectList, REQUEST_CONFIG)
  },

  // 性能数据按条件查询：分页 cxf/nms/alarm/queryterms/
  queryAlarmPaging: function (beginItem, endItem, selectList) {
    return Axios.put(ALARM_PAGING_QUERY + '' + beginItem + '/' + endItem + '/', selectList, REQUEST_CONFIG)
  },

  // 更新告警等级信息 cxf/nms/alarm/alarmlevelconfigbatch
  updateAlarmLevel: function (alarmLevelListUpdate) {
    return Axios.put(ALARMLEVEL_UPDATE, alarmLevelListUpdate, REQUEST_CONFIG)
  },

  // 更新告警配置 cxf/nms/alarmconfig/batch
  updateAlarmConfig: function (alarmCfgListUpdate) {
    return Axios.put(ALARMCFG_UPDATE, alarmCfgListUpdate, REQUEST_CONFIG)
  },

  // 性能数据按条件查询：统计图数据 cxf/nms/alarm/alarmstatistic/
  queryAlarmStatistic: function (statisticsList) {
    return Axios.put(ALARMSTATISTIC_QUERY + '/', statisticsList, REQUEST_CONFIG)
  },

  queryAlarmReport: function (valueTopN, statisticsList) {
    return Axios.put(ALARMREPORT_QUERY + valueTopN + '/', statisticsList, REQUEST_CONFIG)
  },
  /**
   * @Description  : 告警分布统计
   * @author       : ls
   * @date         : 2020/5/12 9:43
   * @param        :
   * @return       :
   */
  queryAlarmDistributionReportApi: function (statisticsList) {
    return Axios.put(ALARMREPORT_QUERY, statisticsList, REQUEST_CONFIG)
  },
  /**
   * @Description  : 报表统计
   * @author       : ls
   * @date         : 2020/5/29 16:13
   * @param        :
   * @return       :
   */
  queryReport: function (val) {
    return Axios.put(REPORT_QUERY, val, REQUEST_CONFIG)
  },

  // 下载告警查询列表excel
  putDownloadAlarmQuery: function (conditionSet) {
    return Axios.put(ALARM_QUERY_DOWNLOAD_EXCEL, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },
  // 下载告警查询列表csv
  putDownloadAlarmQueryCsv: function (conditionSet) {
    return Axios.put(ALARM_QUERY_DOWNLOAD_CSV, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  // 下载
  updownloadAlarmConfig: function (conditionSet) {
    return Axios.put(ALARM_PAGING_QUERY, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  downloadAllAlarmCfgList: function (conditionSet) {
    return Axios.put(ALARMCFGLIST_ADMQ, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  }
}

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