﻿FareBreakup = createClass();
FareBreakup.prototype.init = function(args) {
    /*
        adtBase     : Base fare amount for Adult
        chdBase     : Base fare amount for Child
        infBase     : Base fare amount for Infant
		adtTax      : Tax amount for Adult
        chdTax      : Tax amount for Child
        infTax      : Tax amount for Infant
    */
	defaults = { adtBase: 0, chdBase: 0, infBase: 0, 
	             adtTax: 0, chdTax: 0, infTax: 0 };
	for(var pr in defaults)
		this[pr] = isDefined(args[pr]) ?args[pr] :defaults[pr];

	// Load details from fare json (usually downloaded from server)
    if(!(args instanceof FareBreakup)) {
        if(isDefined(args.ba)) {
            this.adtBase = args.ba;
            this.chdBase = args.bc;
            this.infBase = args.bi;
            this.adtTax = args.ta;
            this.chdTax = args.tc;
            this.infTax = args.ti;
        }
    }    
    // Get property/aggregated value
    this.get = function(pr) {
	    var value = null; 
	    if(/adult/i.test(pr))
            value = { base: this.adtBase, tax: this.adtTax };
	    else if(/child/i.test(pr))
            value = { base: this.chdBase, tax: this.chdTax };
	    else if(/infant/i.test(pr))
            value = { base: this.infBase, tax: this.infTax };
        else if(/base/i.test(pr))
            value = { adt: this.adtBase, chd: this.chdBase, inf: this.infBase };
        else if(/tax/i.test(pr))
            value = { adt: this.adtTax, chd: this.chdTax, inf: this.infTax };
	    else if(isDefined(this[pr]))
		    value = this[pr];
	    return value;
    };
    
    this.add = function(fb2) {
        for(var pr in this)
            if(isNumeric(this[pr]))
                this[pr] += fb2[pr];
    }
};

