let NodeType = {
  Node: 0,   //网元
  Server: 1  //服务器
}

var PerformanceSample = {
  performKey: '',
  nodeType: -1,
  deviceType: '',
  deviceKey: '',
  slotKey: '',
  portName: '',
  performType: '',
  period: -1,
  timestamp: '',
  value: -1.0
}

class PerformanceManagerImplement {
  findPerformanceByKey(PerformanceCollection, PerformanceKey) {
    return PerformanceCollection[PerformanceKey]
  }

  // 根据网元获取权限
  getPerformanceListByNodeTypeNode(PerformanceCollection) {
    let PerformanceListWithNoteType0 = []
    for (var PerformanceKey in PerformanceCollection) {
      let PerformanceInCollection = this.findPerformanceByKey(PerformanceCollection, PerformanceKey)
      if (PerformanceInCollection.nodeType === NodeType.Node) {
        let performance = {}
        performance.performType = PerformanceInCollection.performType
        performance.performKey = PerformanceInCollection.performKey
        PerformanceListWithNoteType0.push(performance)
      }
    }
    return PerformanceListWithNoteType0
  }

  // 根据服务器获取权限
  getPerformanceListByNodeTypeServer(PerformanceCollection) {
    let PerformanceListWithNoteType1 = []
    for (var PerformanceKey in PerformanceCollection) {
      let PerformanceInCollection = this.findPerformanceByKey(PerformanceCollection, PerformanceKey)
      if (PerformanceInCollection.nodeType === NodeType.Server) {
        let performance = {}
        performance.performType = PerformanceInCollection.performType
        performance.performKey = PerformanceInCollection.performKey
        PerformanceListWithNoteType1.push(performance)
      }
    }
    return PerformanceListWithNoteType1
  }

  // 结构体转数组
  perormanceAsArray (PerformanceCollection) {
    return Object.values(PerformanceCollection)
  }
}

let implementMethods = new PerformanceManagerImplement()

function PerformanceManager (PerformanceCollection) {
  // 根据key值获取权限
  function findPerformanceByKey (PerformanceKey) {
    return implementMethods.findPerformanceByKey(PerformanceCollection, PerformanceKey)
  }

  // 根据网元获取权限
  function getPerformanceListByNodeTypeNode () {
    return implementMethods.getPerformanceListByNodeTypeNode(PerformanceCollection)
  }

  // 根据服务器获取权限
  function getPerformanceListByNodeTypeServer () {
    return implementMethods.getPerformanceListByNodeTypeServer(PerformanceCollection)
  }

  function asArray() {
    return implementMethods.devicesAsArray(PerformanceCollection)

  }

  return Object.freeze(Object.assign(
    {
      // 在此列出模型对象方法
      findPerformanceByKey,
      getPerformanceListByNodeTypeNode,
      getPerformanceListByNodeTypeServer,
      asArray
    }
  ))
}

export default PerformanceManager
