var cabinetSmaple = {
  cabinetKey: '',
  cabinetName: '',
  cabinetType: '',
  locationKey: '',
  height: '',
  depth: '',
  width: '',
  frameCount: -1,
  voltage: '',
  delFlag: -1,
  modifyTime: ''
}

class CabinetMgrImplement {
  // 根据key值查找机架
  findCabinetByKey (CabinetCollection, cabinetKey) {
    return CabinetCollection[cabinetKey]
  }

  // 查找机房内的机架
  findLocationCabinet (locationKey, CabinetCollection) {
    let cabinetList = {}
    for (var cabinetKey in CabinetCollection) {
      if (CabinetCollection[cabinetKey].locationKey === locationKey) {
        let cabinet = this.findCabinetByKey(CabinetCollection, cabinetKey)
        cabinetList[cabinetKey] = cabinet
      }
    }
    return cabinetList
  }

  // 结构体转数组
  cabinetAsArray (CabinetCollection) {
    return Object.values(CabinetCollection)
  }
}

let implementMethods = new CabinetMgrImplement()

var staticMethods = {
  createDeviceSample: function () {
    return Object.freeze(Object.assign({}, cabinetSmaple))
  }
}

function CabinetManager (CabinetCollection) {
  // 根据key值获取机架
  function findCabinetByKey (cabinetKey) {
    return implementMethods.findCabinetByKey(CabinetCollection, cabinetKey)
  }

  // 查找机房内的机架
  function findLocationCabinet (locationKey) {
    return implementMethods.findLocationCabinet(locationKey, CabinetCollection)
  }

  function asArray() {
    return implementMethods.cabinetAsArray(CabinetCollection)
  }

  return Object.freeze(Object.assign(
    {
      findCabinetByKey,
      findLocationCabinet,
      asArray
    },
    staticMethods
  ))
}

export default CabinetManager
