# Jared Wasserman
# 5/19/2013
# Python translation of Arup's program to test BankAccount class

from BankAccount import BankAccount

class TestBank:

    # Prints menu of possible choices to user.
    @staticmethod
    def menu():  

        print("Welcome to the Banking Program.") 
        print("Enter your choice, remember you can only create an account once.") 
        print("1. Create an Account.") 
        print("2. Deposit money.") 
        print("3. Write a check.") 
        print("4. Change your account interest rate.") 
        print("5. Mature account one year.") 
        print("6. Print out account information.") 
        print("7. Quit") 

    # Creates a BankAccount object based on information user enters, and
    # returns a reference to this object.
    @staticmethod
    def createAccount():
        name = str(input("Enter your name.\n"))
        save = float(input("Enter your initial savings deposit.\n"))
        check = float(input("Enter your initial checking deposit.\n"))
    
        # Does not create account if information is invalid.
        if (save < 0 or check < 0):
            print("Sorry no account created, need non-negative values in savings and checking accounts.") 
        else:
            print("You have a new account with a 5% interest rate.") 
            b = BankAccount(name, save, check, 0.05) 
            return b 
         
        return None 

    # Asks user for deposit information and executes transaction if values
    # entered are valid.
    @staticmethod
    def deposit(b):
    
        money = float(input("Enter how much you would like to deposit.\n"))
        
        if (money > 0):
            ans = str(input("Which account, (S)avings or (C)hecking?\n")).upper()[0] 
            
            if (ans == 'S'):
                b.deposit_sav(money) 
            elif (ans == 'C'):
                b.deposit_chk(money) 
            else:
                print("Sorry, invalid choice.") 
         
        else:
            print("Can not deposit negative money.")    

    # Asks user for withdraw amount and withdraws if sufficient funds are
    # in their Bank Account. Proper error message is printed if withdrawl is
    # not executed.
    @staticmethod
    def withdraw(b): 
    
        money = float(input("Enter the amount to withdraw.\n")) 
    
        if (money > 0):
            if (b.noBounce(money)):
                b.withdraw_chk(money) 
            else:
                print("Sorry, you do not have enough money in your checking account.") 
         
        else:
            print("Sorry, you can not withdraw negative money.") 

    # Changes the interest rate of the Bank Account passed in as a parameter
    # as long as the user has sufficient funds to pay for the increased rate.
    @staticmethod
    def changeRate(b):
    
        print("Enter new interest rate.") 
        print("Keep in mind that you will be charged $500 for each percentage point you raise your interest rate.") 
        rate = float(input())
    
        if (rate <= b.getIrate()):
            print("You can not decrease your interest rate.") 
        else:
            charge = 500 * (100 * (rate - b.getIrate())) 
            if (b.noBounce(charge)):  
                b.changeRate(rate) 
                b.withdraw_chk(charge) 
             
            else:
                print("You do not have sufficient funds to raise your rate that much.")
                
def main():  
    # Initialize BankAccount reference variable.
    b1 = None 
    # Print menu and get the user's choice
    TestBank.menu() 
    menu_choice = int(input()) 

    # Loops till user wants to quit application
    while (menu_choice != 7):
        
        # Processes user choice, note that by checking if the b1 reference
        # variable is None, the user is only allowed to do options 2
        # through 7 if they have created a BankAccount object.
        if (menu_choice == 1):
        
            if (b1 == None):
                b1 = TestBank.createAccount()
            else:
                print("Sorry you have already created an account.") 
             
        elif (b1 == None):
            print("You can not attempt any operations without creating an account first.") 
        elif (menu_choice == 2):
            TestBank.deposit(b1) 
        elif (menu_choice == 3):
            TestBank.withdraw(b1) 
        elif (menu_choice == 4):
            TestBank.changeRate(b1) 
        elif (menu_choice == 5):
            b1.matureAccount() 
        elif (menu_choice == 6):
            b1.printInfo() 
        elif (menu_choice != 7):
            print("Invalid choice.") 

        TestBank.menu() 
        menu_choice = int(input()) 
        
        print("Thank you for using the banking program.")

# runs main module on startup
if __name__ == "__main__":
    main()
