#
# Copyright 2023, Ali Arya
# Anyone Can Code: Algorithmic Thinking
# Example 5.9p
#

#Record types
class Transaction:
    """A simple transaction class/record"""
    account = 0
    type = " "
    amount = 0

class Account:
    """A simple account class/record"""
    number = 0
    name = " "
    balance = 0

#Global variables
accounts = []
transactions = []
trtypes = ["Report", "Deposit", "Withdraw"]

#Functions
def GetAccount(i):
    acc = Account()
    acc.number = 1000+i #start from 1000
    acc.name = input ("Enter account holder's name: ")
    acc.balance = 0
    return acc

def PrintAccount(acc):
    print("Account:")
    print("Account #: ", acc.number)
    print("Name: ", acc.name)
    print("Balance: ", acc.balance)

def GetTransaction():
    tr = Transaction()
    tr.account = int(input ("Enter account number: "))
    tr.type = int(input ("Enter transaction type (1-Report, 2-Deposit, 3-Withdraw): "))
    tr.amount = int(input ("Enter transaction amount: "))
    return tr

def PrintTransaction(tr):
    print("Transaction:")
    print("Account #: ",tr.account)
    print("Type: ",trtypes[tr.type-1])
    print("Amount: ", tr.amount)

def RunTransaction(tr):
    PrintTransaction(tr)
    if tr.type == 1:
        PrintAccount(accounts[tr.account-1000])
    elif tr.type == 2:
        accounts[tr.account-1000].balance += tr.amount
        PrintAccount(accounts[tr.account-1000])
    elif tr.type == 2:
        accounts[tr.account-1000].balance -= tr.amount
        PrintAccount(accounts[tr.account-1000])
    else:
        print("Invalid transaction")

def Init():
    global accounts
    for i in range(3):
        accounts.append(GetAccount(i))
    for i in range(3):
        PrintAccount(accounts[i])


def Loop():
    global accounts, transactions

    quit = False
    while not quit:
        command = int(input("0-Exit, 1-Create Transaction, 2-Run Transaction, 3-List Transactions: "))
        if command == 0:
            quit = True
        elif command == 1:
            newTransaction = GetTransaction()
            transactions.append(newTransaction)
        elif command == 2:
            currentTransaction = transactions[0]
            RunTransaction(currentTransaction)
            transactions.remove(currentTransaction)
        elif command == 3:
            for i in range(len(transactions)):
                PrintTransaction(transactions[i])
        else:
            print("invalid command")



# Main code
Init()
Loop()