#include "withdraw_2.h"

// Author: Steve Talbot

withdraw_2:: withdraw_2(){
}

withdraw_2:: ~withdraw_2(){
}

bool withdraw_2:: withdraw( Data* data_, MDA_EFSM* M_ ){

	bool isLessThanMinBalance = false;

	// calculate the “withdraw” operation ..

	int currentBalance = data_->getCurrentAccountInfo()->getB();
	int withdrawAmount = data_->getW();

	int result = ( currentBalance - withdrawAmount );

	// check whether this is an “overdraw” ..

	int minBalance = data_->getMinBalance();

	if( result < minBalance )
		isLessThanMinBalance = true;

	// "alternate" configuration ..
	AccountInfo* accountInfo = data_->getCurrentAccountInfo();
	int id = accountInfo->getID();
	cout << "id: " << id << ", min balance: " << minBalance << ", withdraw: " << withdrawAmount << ", new balance: " << result << endl;

	M_->withdraw( isLessThanMinBalance );

	return isLessThanMinBalance;


}
