MENU = {
    "espresso": {
        "ingredients": {
            "water": 50,
            "coffee": 18,
        },
        "cost": 1.5,
    },
    "latte": {
        "ingredients": {
            "water": 200,
            "milk": 150,
            "coffee": 24,
        },
        "cost": 2.5,
    },
    "cappuccino": {
        "ingredients": {
            "water": 250,
            "milk": 100,
            "coffee": 24,
        },
        "cost": 3.0,
    }
}

resources = {
    "water": 300,
    "milk": 200,
    "coffee": 100,
    "money": 0.0,
}

b_is_on = True

def print_report():
        print(f"Water: {str(resources['water'])} ml")
        print(f"Milk: {str(resources['milk'])} ml")
        print(f"Coffe: {str(resources['coffee'])} ml")
        print(f"Money: ${str(resources['money'])}")

def check_resources(drink):
    for ingredient in MENU[drink]['ingredients']:
        if MENU[drink]['ingredients'][ingredient] > resources[ingredient]:
            print(f'Sorry there is not enough {ingredient}')
            return False
    return True

def collect_coins(drink):
    coins = {
        "quarters": 0.25,
        "dimes": 0.10,
        "nickels": 0.05,
        "pennies": 0.01,
    }
    print("Please insert coins.")

    total_input = 0
    for coin in coins:
        coins_number = input(f"How many {coin}? ")
        total_input += int(coins_number) * coins[coin]
    
    if total_input < MENU[drink]['cost']:
        print("Sorry that's not enough money. Money refunded.")
        return False
    else:
        if total_input > MENU[drink]['cost']:
            print(f"Here is ${total_input - MENU[drink]['cost']} in change.")      
        resources['money'] = total_input + resources['money']
        return True

def make_drink(drink):
        for ingredient in MENU[drink]['ingredients']:
            resources[ingredient] = MENU[drink]['ingredients'][ingredient] - resources[ingredient]
        print(f"Here is your {drink} ☕️. Enjoy!")

def prepare_drink(drink):
    if drink not in MENU.keys():
        print("Invalid drink - Try again")
        return
    if not check_resources(drink):
        return
    
    if not collect_coins(drink):
        return
    
    make_drink(drink)

while b_is_on == True:
    choice = input('What would you like? (espresso/latte/cappuccino):')

    match(choice):
        case "off":
            b_is_on = False
        case "report":
            print_report()
        case _:
            prepare_drink(choice)