/**
 *  性能配置服务
 */
import HelperUtil from '../../utils/HelperUtil'
import PerformanceMonitorAPI from '../../api/restApis/PerformanceMonitorAPI'
import {PERFORMANCE_CONFIG_KEY, PERFORMANCE_TYPE_KEY} from '../../utils/constantCollection'

// 静态方法
let staticMethods = {
  /**
   * @Description  : 修改启用停用
   * @author       : ls
   * @date         : 2020/4/26 10:57
   * @param        :
   * @return       :
   */
  postChangeStatus: function (val) {
    return PerformanceMonitorAPI.putPerformanceMonitor(val).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 查询
   * @author       : ls
   * @date         : 2020/4/26 12:52
   * @param        :
   * @return       :
   */
  serviceConditionQueryThreshold: function (val) {
    return PerformanceMonitorAPI.apiConditionQueryThreshold(val).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject1(result.data.returnValue, PERFORMANCE_CONFIG_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 获取所有性能配置
  getAllPerformanceMonitorCollection: function () {
    return PerformanceMonitorAPI.getAllPerformanceMonitorCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject1(result.data.returnValue, PERFORMANCE_CONFIG_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  // 获取所有性能事件
  getAllPerformanceTypeCollection: function () {
    return PerformanceMonitorAPI.getAllPerformanceTypeCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, PERFORMANCE_TYPE_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  // 修改性能配置
  modifyPerformanceMonitor: function (formRow) {
    return PerformanceMonitorAPI.putPerformanceMonitor(formRow).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

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