import config from 'shared/config/index' ; import { Node } from 'core/util/tree' ; import { FactorType , ReferredUserFactor , FactorAction } from 'core/repository/referredUsers/interfaces' ; export default class FactorNode < T > extends Node < T > { private readonly levelSummary : Array < ReferredUserFactor > ; constructor ( data ) { super ( data ) ; this . levelSummary = new Array ( config . CONSTANTS . REFERRAL . MAX_COUNT + 1 ) ; for ( let i = 1 ; i <= config . CONSTANTS . REFERRAL . MAX_COUNT ; i ++ ) { this . levelSummary [ i ] = ReferredUserFactor . createEmpty ( ) ; } } private idLevelValid ( level ) { return level >= 1 && level <= config . CONSTANTS . REFERRAL . MAX_COUNT ; } getFactorsByLevel ( level ) { if ( this . idLevelValid ( level ) ) { return this . levelSummary [ level ] ; } return ReferredUserFactor . createEmpty ( ) ; } addFactor ( type , level , value , action ) { for ( let i = 1 ; i <= config . CONSTANTS . REFERRAL . MAX_COUNT - level ; i ++ ) { const factor = this . levelSummary [ i ] ; factor . update ( type , value , action ) ; } } }