#include "CheckPin.h"

// Author: Steve Talbot

CheckPin:: CheckPin(){

}

CheckPin:: ~CheckPin(){
}

bool CheckPin:: correct_pin( bool isAboveMinBalance_, bool isActive_, int& nextStateId_ ){

	// “isAboveMinBalance_” and “isActive_” passed in from the Account..

	if( isActive_ ) {

		// go to “READY” or “OVERDRAWN” states ..
		return active( isAboveMinBalance_, nextStateId_ );

	} else {

		// go to “INACTIVE” state ..
		return inactive( nextStateId_ );

	}

}

bool CheckPin:: incorrect_pin( bool attemptsRemain_, int& nextStateId_ ){

	// “attemptsRemain_” passed in from the Account..

	bool result = false;

	if( attemptsRemain_ == true ){

		result = attempts_remain();

		return result;

	} else {

		result = too_many_attempts( nextStateId_ );

		return result;

	}

}

bool CheckPin:: attempts_remain(){

	bool result = getOutputProcessor()->incorrect_pin_msg();

	return result;

}

bool CheckPin:: too_many_attempts( int& nextStateId_ ){

	nextStateId_ = _stateIds->IDLE;

	bool result = getOutputProcessor()->too_many_attempts_msg();

	// reset the number of "attempts" for the next round ..
	getOutputProcessor()->resetNumberOfAttempts();

	return result;

}

bool CheckPin:: active( bool isAboveMinBalance_, int& nextStateId_ ){

	// “isAboveMinBalance_” passed in from the Account..

	if( isAboveMinBalance_ == true ){

		return above_min_balance( nextStateId_ );

	} else {

		return below_min_balance( nextStateId_ );

	}

}

bool CheckPin:: inactive( int& nextStateId_ ){

	nextStateId_ = _stateIds->INACTIVE;

	bool result = getOutputProcessor()->deactivate_msg();

	// reset the number of "attempts" for the next round ..
	getOutputProcessor()->resetNumberOfAttempts();

	getOutputProcessor()->display_menu();

	return result;

}

bool CheckPin:: above_min_balance( int& nextStateId_ ){

	nextStateId_ = _stateIds->READY;

	// reset the number of "attempts" for the next round ..
	getOutputProcessor()->resetNumberOfAttempts();

	bool result = getOutputProcessor()->display_menu();

	return result;

}

bool CheckPin:: below_min_balance( int& nextStateId_ ){

	nextStateId_ = _stateIds->OVERDRAWN;

	// reset the number of "attempts" for the next round ..
	getOutputProcessor()->resetNumberOfAttempts();

	bool result = getOutputProcessor()->display_menu();

	return result;

}

// these are only necessary if the parent class defines these
// methods are "abstract" (i.e.: pure virtual) methods ..

//bool CheckPin:: correct_login( int& nextStateId_ ){/* empty implementation */ return false; }							// Idle();
//bool CheckPin:: incorrect_login(){/* empty implementation */ return false; }											// Idle();
//bool CheckPin:: logout( int& nextStateId_ ){/* empty implementation */ return false; }								// Inactive(); Overdrawn(); Ready();

//bool CheckPin:: correct_pin( int& nextStateId_ ){/* empty implementation */ return false; }							// Overdrawn(); Ready();
//bool CheckPin:: correct_pin( bool isAboveMinBalance_, int& nextStateId_ ){/* empty implementation */ return false; }	// Inactive();

//bool CheckPin:: incorrect_pin(){/* empty implementation */ return false; }											// Inactive(); Overdrawn(); Ready();

//bool CheckPin:: activate( bool isPinCorrect_, bool isAboveMinBalance_, int& nextStateId ){/* empty implementation */ return false; }	// Inactive();
//bool CheckPin:: deactivate( bool isPinCorrect_, int& nextStateId_ ){/* empty implementation */ return false; }		// Overdrawn(); Ready();

//bool CheckPin:: balance(){/* empty implementation */ return false; }													// Inactive(); Overdrawn(); Ready();
//bool CheckPin:: withdraw( bool isLessThanMinBalance_, int& nextStateId_ ){/* empty implementation */ return false; }	// Inactive(); Overdrawn(); Ready();
//bool CheckPin:: deposit( bool isLessThanMinBalance_, int& nextStateId_ ){/* empty implementation */return false;  }	// Inactive(); Overdrawn(); Ready();

//bool CheckPin:: diff_more_or_equal_to_min_balance(){/* empty implementation */ return false; }						// Ready();
//bool CheckPin:: diff_less_than_min_balance( int& nextStateId_ ){/* empty implementation */ return false; }			// Ready();

//bool CheckPin:: sum_more_or_equal_to_min_balance( int& nextStateId_ ){/* empty implementation */ return false; }		// Overdrawn();
//bool CheckPin:: sum_less_than_min_balance(){/* empty implementation */ return false; }								// Overdrawn();
