#include "make_deposit_1.h"

// Author: Steve Talbot

make_deposit_1:: make_deposit_1(){
}

make_deposit_1:: ~make_deposit_1(){
}

bool make_deposit_1:: make_deposit( Data* data_ ){

	AccountInfo* accountInfo = data_->getCurrentAccountInfo();

	int currentBalance = accountInfo->getB();

	int depositAmount = data_->getD();

	int result = ( currentBalance + depositAmount );

	// check to see if new “result” is greater than or equal to the min balance,
	// if so, change “overdrawn” account parameter to indicate
	// that state is no longer “overdrawn” ..

	if( result >= data_->getMinBalance() ) {

		// this indicates that the new “result” changes the current state
		// from “overdrawn” to “not overdrawn”  ..

		if( accountInfo->getIsOverdrawn() == true )
			accountInfo->setIsOverdrawn( false );

	}

	// update the “account” with the new balance ..
	accountInfo->setB( result );

	// indicate that this change to the "account info" object means
	// that this object needs to be written to file during the logout operation ..
	if ( data_->getNeedsToBeFlushedToFile( accountInfo->getID() ) == false )
		data_->setNeedsToBeFlushedToFile( accountInfo->getID(), true );

	return true;

}
