package cs201.roles.bankRoles;

import cs201.agents.PersonAgent.Intention;
import cs201.interfaces.roles.bank.BankTeller;
import cs201.roles.Role;


public class BankTellerRole extends Role implements BankTeller {
	
	//================================================================================
    // Member Variables
    //================================================================================
	
	MyCustomer currentCustomer;
	TellerState state;
	
	public enum CustomerAction { OpenAccount, WithdrawMoney, DepositMoney, TakeOutLoan }
	private class MyCustomer {
	    BankCustomerRole currentCustomer;
	    CustomerAction action;
	    int accountNumber;
	    double availableBalance;
	    double transactionAmount;
	}
	
	public enum TellerState {
	    Unoccupied,
	    OpeningAccount,
	    WithdrawingMoney,
	    DepositingMoney,
	    AssessingLoan
	}
	
	//================================================================================
    // Scheduler
    //================================================================================
	
	public boolean pickAndExecuteAnAction() {
		if (currentCustomer.state == OpenAccount) {
			openAccount();
		}
		if (currentCustomer.state == WithdrawMoney) {
			withdrawMoney();
		}
		if (currentCustomer.state == DepositMoney) {
			depositMoney();
		}
		if (currentCustomer.state == TakeOutLoan) {
			assessLoan();
		}
        return false;
	}
	
	//================================================================================
    // Messages
    //================================================================================
	
	public void msgOpenAccount(BankCustomerRole cust, double startingBalance) {
	    currentCustomer = new MyCustomer(cust, CustomerAction.OpenAccount, startingBalance);
	    stateChanged();
	}
	
	public void msgDepositMoney(BankCustomerRole cust, int actNum, double amtToDeposit) {
	    currentCustomer = new MyCustomer(cust, CustomerAction.DepositMoney, actNum, amtToDeposit);
	    stateChanged();
	}
	
	public void msgWithdrawMoney(BankCustomerRole cust, int actNum, double amtToWithdraw) {
	    currentCustomer = new MyCustomer(cust, CustomerAction.WithdrawMoney, actNum, amtToWithdraw);
	    stateChanged();
	}
	
	public void msgRequestMoney(BankCustomerRole cust, int actNum, double amtRequested) {
	    currentCustomer = new MyCustomer(cust, CustomerAction.TakeOutLoan, actNum, amtRequested);
	    stateChanged();
	}
	
	//================================================================================
    // Actions
    //================================================================================

	private void openAccount() {
	    // Create an account number
	    
	    Bank.addAccount(actNum, currentCustomer.transactionAmount);
	    currentCustomer.getCustomer.msgAccountIsOpened(actNum); 
	    Bank.getGuard.msgDoneWithCustomer(this);
	}
	
	private void depositMoney() {
	    Bank.addMoneyToAccount(currentCustomer.getAccountNum, currentCustomer.getTransactionAmount);
	    
	    myCustomer.getCustomer.msgMoneyIsDeposited(Bank.getAccountBalance(currentCustomer.getAccountNum)); 
	    Bank.getGuard.msgDoneWithCustomer(this);
	}
	
	private void withdrawMoney() {
	    if (Bank.getAccountBalance(currentCustomer.getAccountNum) > transationAmount) {
	        Bank.subtractMoneyFromAccount(currentCustomer.getAccountNum, currentCustomer.getTransactionAmount);
	        myCustomer.getCustomer.msgMoneyIsWithdrawn(Bank.getAccountBalance(currentCustomer.getAccountNum));
	    }
	    else { // Overdrawn account, give them remaining balance
	        Bank.subtractMoneyFromAccount(currentCustomer.getAccountNum, Bank.getAccountBalance(currentCustomer.getAccountNum));
	        myCustomer.getCustomer.msgOverdrawnAccount();
	    }
	    Bank.getGuard.msgDoneWithCustomer(this);
	}
	
	private void takeOutLoan() {
	    if (Bank.getBankBalance > currentCustomer.getTransactionAmount) {
	        myCustomer.getCustomer.msgLoanGranted();
	    }
	    else {
	         myCustomer.getCustomer.msgLoanDenied();
	    }
	    Bank.getGuard.msgDoneWithCustomer(this);
	}

	@Override
	public void startInteraction(Intention intent) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void closingTime() {
		// TODO Auto-generated method stub
		
	}
}

@@ -140,16 +140,51 @@
 s.Role;%0A
+import cs201.structures.bank.Bank;%0A
 %0A%0Apublic
@@ -1132,16 +1132,18 @@
 n() %7B%0A%09%09
+/*
 if (curr
@@ -1408,16 +1408,18 @@
 n();%0A%09%09%7D
+*/
 %0A       
@@ -1701,32 +1701,34 @@
 Balance) %7B%0A%09    
+//
 currentCustomer 
@@ -1906,32 +1906,34 @@
 Deposit) %7B%0A%09    
+//
 currentCustomer 
@@ -2119,32 +2119,34 @@
 ithdraw) %7B%0A%09    
+//
 currentCustomer 
@@ -2336,24 +2336,26 @@
 ted) %7B%0A%09    
+//
 currentCusto
@@ -2715,24 +2715,26 @@
 %0A%09    %0A%09    
+//
 Bank.addAcco
@@ -2786,16 +2786,18 @@
 );%0A%09    
+//
 currentC
@@ -2811,24 +2811,26 @@
 .getCustomer
+()
 .msgAccountI
@@ -2844,32 +2844,34 @@
 (actNum); %0A%09    
+//
 Bank.getGuard.ms
@@ -2932,24 +2932,26 @@
 ey() %7B%0A%09    
+//
 Bank.addMone
@@ -2982,32 +2982,34 @@
 er.getAccountNum
+()
 , currentCustome
@@ -3022,32 +3022,34 @@
 ransactionAmount
+()
 );%0A%09    %0A%09    my
@@ -3042,24 +3042,26 @@
 %0A%09    %0A%09    
+//
 myCustomer.g
@@ -3158,32 +3158,34 @@
    Bank.getGuard
+()
 .msgDoneWithCust
@@ -3230,32 +3230,34 @@
 wMoney() %7B%0A%09    
+/*
 if (Bank.getAcco
@@ -3831,32 +3831,34 @@
 hCustomer(this);
+*/
 %0A%09%7D%0A%09%0A%09private v
@@ -3882,16 +3882,18 @@
  %7B%0A%09    
+/*
 if (Bank
@@ -4086,32 +4086,34 @@
    Bank.getGuard
+()
 .msgDoneWithCust
@@ -4119,24 +4119,26 @@
 tomer(this);
+*/
 %0A%09%7D%0A%0A%09@Overr

Fix errors in BankTellerRole