#include "Account.h"

// Author: Steve Talbot

Account:: Account(){

	// set initial values for the "Data" data structure,
	// these values are "system parameters" which can be
	// configured via a menu selection ..
	_data = new Data();
	_data->setMinBalance( 0 );
	_data->setOverdrawPenalty( 25 );
	_data->setMaxAttempts( 3 );
	_data->setAttempts( 0 );
	_data->setFileDrive( "C:\\" );
	_data->setFileDirectory( "Temp\\" );
	_data->setFileName( "Bank_Accounts.bin" );

	// the "OP" has a pointer to the "Data" data structure ..
	_OP = new OutputProcessor( _data );

	// the "model" has a pointer to the "OP" ..
	_M = new MDA_EFSM( _OP );

	// initialize the method wrappers with default configuration ..
	_OA = new open_account_1();

	_LI = new login_1();

	_PI = new pin_1();

	_LO = new logout_1();

	_BA = new balance_1();

	_W = new withdraw_1();

	_D = new deposit_1();

	_A = new activate_1();

	_DA = new deactivate_1();

}

Account:: ~Account(){

	if( _data != NULL ) delete _data;

	if( _OP != NULL ) delete _OP;

	if( _M != NULL ) delete _M;

	if( _OA != NULL ) delete _OA;

	if( _LI != NULL ) delete _LI;

	if( _PI != NULL ) delete _PI;

	if( _LO != NULL ) delete _LO;

	if( _BA != NULL ) delete _BA;

	if( _W != NULL ) delete _W;

	if( _D != NULL ) delete _D;

	if( _A != NULL ) delete _A;

	if( _DA != NULL ) delete _DA;

}

void Account:: removeCurrentConfiguration(){

	// delete the configurable method wrappers in preparation
	// for a new configuration ..

	if( _LI != NULL ) delete _LI;

	if( _PI != NULL ) delete _PI;

	if( _BA != NULL ) delete _BA;

	if( _W != NULL ) delete _W;

	if( _D != NULL ) delete _D;

}

bool Account:: open_account( int p_, int y_, int a_ ){

	if( _OA != NULL )
		return _OA->open_account( p_, y_, a_, _data, _M );
	return false;
}

bool Account:: login( int y_ ){

	if( _LI != NULL )
		return _LI->login( y_, _data, _M );
	return false;

}

bool Account:: pin( int p_ ){

	if( _PI != NULL )
		return _PI->pin( p_, _data, _M );
	return false;

}

bool Account:: logout(){

	if( _LO != NULL )
		return _LO->logout( _data, _M );
	return false;

}

bool Account:: balance(){

	if( _BA != NULL )
		return _BA->balance( _M );
	return false;

}

bool Account:: withdraw( int w_ ){

	if( _W != NULL ) {

		// store “w” in “data” for later use in OP ..
		_data->setW( w_ );

		return _W->withdraw( _data, _M  );

	}

	// if W == NULL, withdraw not performed ..
	return false;

}

bool Account:: deposit( int d_ ){

	if( _D != NULL ) {

		// store “d” in “data” for later use in OP ..
		_data->setD( d_ );

		return _D->deposit( _data, _M );

	}

	// if D == NULL, deposit not performed ..
	return false;

}

bool Account:: activate(){

	if( _A != NULL )
		return _A->activate( _data, _M );

	// if A == NULL, activate not performed ..
	return false;

}

bool Account:: deactivate(){

	if( _DA != NULL )
		return _DA->deactivate( _data, _M );
	return false;

}

/*
 * SETTERS ..
 */

void Account:: setMDA_EFSM( MDA_EFSM* M_ ){

	if( _M != NULL ) delete _M;

	_M = M_;

}

void Account:: setOutputProcessor( OutputProcessor* OP_ ){

	if( _OP != NULL ) delete _OP;

	_OP = OP_;

}

void Account:: setOpenAcountA( open_account_a* OA_ ){

	if( _OA != NULL ) delete _OA;

	_OA = OA_;

}

void Account:: setLoginA( login_a* LI_ ){

	if( _LI != NULL ) delete _LI;

	_LI = LI_;

}

void Account:: setPinA( pin_a* PI_ ){

	if( _PI != NULL ) delete _PI;

	_PI = PI_;

}

void Account:: setLogoutA( logout_a* LO_ ){

	if( _LO != NULL ) delete _LO;

	_LO = LO_;

}

void Account:: setBalanceA( balance_a* BA_ ){

	if( _BA != NULL ) delete _BA;

	_BA = BA_;

}

void Account:: setWithdrawA( withdraw_a* W_ ){

	if( _W != NULL ) delete _W;

	_W = W_;

}

void Account:: setDepositA( deposit_a* D_ ){

	if( _D != NULL ) delete _D;

	_D = D_;

}

void Account:: setActivateA( activate_a* A_ ){

	if( _A != NULL ) delete _A;

	_A = A_;

}

void Account:: setDeactivateA( deactivate_a* DA_ ){

	if( _DA != NULL ) delete _DA;

	_DA = DA_;

}

void Account:: setMinBalance( int minBalance_ ){

	_data->setMinBalance( minBalance_ );

}

void Account:: setOverdrawPenalty( int overdrawPenalty_ ){

	_data->setOverdrawPenalty( overdrawPenalty_ );

}

void Account:: setMaxAttempts( int maxAttempts_ ){

	_data->setMaxAttempts( maxAttempts_ );

}



/*
 * GETTERS ..
 */

MDA_EFSM* Account:: getMDA_EFSM(){

	return _M;

}

OutputProcessor* Account:: getOutputProcessor(){

	return _OP;

}

open_account_a* Account:: getOpenAcountA(){

	return _OA;

}

login_a* Account:: getLoginA(){

	return _LI;

}

pin_a* Account:: getPinA(){

	return _PI;

}

logout_a* Account:: getLogoutA(){

	return _LO;

}

balance_a* Account:: getBalanceA(){

	return _BA;

}

withdraw_a* Account:: getWithdrawA(){

	return _W;

}

deposit_a* Account:: getDepositA(){

	return _D;

}

activate_a* Account:: getActivateA(){

	return _A;

}

deactivate_a* Account:: getDeactivateA(){

	return _DA;

}

string Account:: getState(){

	return _M->getCurrentState()->getDescription();

}

int Account:: getStateID(){

	return _M->getCurrentState()->getID();

}

int Account:: getMinBalance(){

	return _data->getMinBalance();

}

int Account:: getOverdrawPenalty(){

	return _data->getOverdrawPenalty();

}

int Account:: getMaxAttempts(){

	return _data->getMaxAttempts();

}

bool Account:: getIsActive(){

	return _data->getCurrentAccountInfo()->getIsActive();

}

bool Account:: getIsOverdrawn(){

	return _data->getCurrentAccountInfo()->getIsOverdrawn();

}

int Account:: getAttempts(){

	return _data->getAttempts();

}