#include "open_account_1.h"

// Author: Steve Talbot

open_account_1:: open_account_1(){
}

open_account_1:: ~open_account_1(){
}

bool open_account_1:: open_account( int p_, int y_, int a_, Data* data_, MDA_EFSM* M_ ){

	// account should not exist in memory,
	// account should not exist in file ..
	if( ( data_->hasAccountInfo( y_ ) == false ) &&
		( data_->hasFileAccountInfo( y_ ) == false ) ) {

		AccountInfo* currentAccountInfo = new AccountInfo( p_, y_, a_ );

		data_->addAccountInfo( currentAccountInfo );

		data_->setCurrentAccountInfo( currentAccountInfo );

		// need to write this new "account info" object to file immediately ..
		data_->writeAccountInfoToFile( data_->findAccountIndex( y_ ) );

		M_->open_account();

		return true;

	}

	// shouldn’t open an account that already exists ..
	return false;

}
