/** 
 * @author Andy Tong
 */
if (Calculators == undefined) {
    var Calculators = {};
}
if (Calculators.planning == undefined) {
    Calculators.planning = {};
}

var MONTHS = 12;
var FORMULA = new Calculators.math.Formulas();

Calculators.planning.SavingsGoal = function SavingsGoal(rate, years, savings, initial) {
	this.rate = new Calculators.type.Rate(rate);
	this.years = new Number(years);
	this.savings = new Calculators.type.Money(savings);
	this.initial = new Calculators.type.Money(initial);
	this.statements = [];
	
	for (var year = 0; year <= years; ++year) {
		var balance = -FORMULA.fv(this.rate.getAmount() / MONTHS, year * MONTHS,
				this.savings.getAmount(), this.initial.getAmount(), false);
	    this.statements[year] = new Calculators.loan.Statement(balance, 0.00, 0.00);
	}
	
	this.getSavings = function() {
		return this.savings;
	}
	
	this.getInitialInvestment = function() {
		return this.initial;
	}
	
	this.getRate = function() {
		return this.rate;
	}
	
	this.getYears = function() {
		return this.years;
	}
	
    /**
     * Retrieves statement information about a particular year.
     *
     * @param year What year to retrieve information about.
     */
	this.getYearlyStatement = function(year) {
		if ((year < 0) || (year > this.years)) {
			throw year + " is not a valid year for this savings period.  Year"
			    + " must be between 0 and " + this.years;
		}
		
		return this.statements[year];
	}
}
