var serverSample = {
  serverKey: '',
  serverName: '',
  serverType: '',
  ipAddress: '',
  snmpVersion: '',
  snmpPort: -1,
  trapPort: -1,
  delFlag: -1,
  modifyTime: '',
  status: -1
}

class ServerMgrImplement {
  //根据key值查找服务器
  findServerByKey (serverCollection, serverKey) {
    return serverCollection[serverKey]
  }

  // 查找SDNC服务器
  getSDNCServer (serverCollection) {
    let SDNCServerList = {}
    for (var serverKey in serverCollection) {
      let server = this.findServerByKey(serverCollection, serverKey)
      if (server.serverType === "0") {
        SDNCServerList[serverKey] = server
      }
    }
    return SDNCServerList
  }

  // 获取SDNC以外的服务器
  getOtherServer (serverCollection) {
    let otherServerList = {}
    for (var serverKey in serverCollection) {
      let server = this.findServerByKey(serverCollection, serverKey)
      if (server.serverType !== "0") {
        otherServerList[serverKey] = server
      }
    }
    return otherServerList
  }

  // 结构体转换数组
  serverAsArray (serverCollection) {
    return Object.values(serverCollection)
  }
}

let implementMethods = new ServerMgrImplement()

var staticMethods = {
  creatServerSample: function () {
    return Object.freeze(Object.assign({}, serverSample))
  }
}

function ServerManager (serverCollection) {
  // 根据key值寻找服务器
  function findServerByKey (serverKey) {
    return implementMethods.findServerByKey(serverCollection, serverKey)
  }

  // 获取SDNC服务器
  function getSDNCServer () {
    return implementMethods.getSDNCServer(serverCollection)
  }

  // 结构体转数组
  function asArray () {
    return implementMethods.serverAsArray(serverCollection)
  }

  // 获取SDNC以外的服务器
  function getOtherServer () {
    return implementMethods.getOtherServer(serverCollection)
  }

  return Object.freeze(Object.assign(
    {
      findServerByKey,
      getSDNCServer,
      getOtherServer,
      asArray
    },
    staticMethods
  ))
}

export default ServerManager
