"""
pizza_bot.py  -  Mario's Pizzeria Automated Ordering Kiosk
===========================================================
Asks the customer a few questions, works out the bill, and prints a summary.

Steps (in the order the brief asks for them):
  1. Welcome message
  2. Customer name + pizza size (Small $10 / Large $15)
  3. Dietary checks: Gluten-Free base (+$3), Dairy-Free cheese (+$2), Vegetarian toppings
  4. Extensions: Garlic Bread (+$4), Delivery (+$5)
  5. Final order summary

The finished order is also saved to last_order.json so pizza_turtle.py
can draw it.  (Shelly the turtle is waiting!)
"""

import json


# ---------- helper functions ----------

def ask_yes_no(question):
    """Keep asking until the customer types yes or no. Returns True for yes."""
    while True:
        answer = input(question + " (yes/no)\n").strip().lower()
        if answer in ("yes", "y"):
            return True
        if answer in ("no", "n"):
            return False
        print("Please type yes or no.")


def ask_choice(question, options):
    """Keep asking until the answer is one of the options (e.g. small/large)."""
    while True:
        answer = input(question + "\n").strip().lower()
        if answer in options:
            return answer
        print("Please type one of: " + " or ".join(options))


# ---------- 1. Welcome message ----------

print("====================================")
print("       MARIO'S PIZZERIA KIOSK       ")
print("====================================")

# ---------- 2. Customer details & base pizza ----------

name = input("What is your name?\n").strip().title()

size = ask_choice("Would you like a Small ($10) or Large ($15) pizza?", ["small", "large"])

# Base price setup (if/else)
if size == "small":
    total_cost = 10
else:
    total_cost = 15

# ---------- 3. Dietary & allergy checks ----------

print(" --- DIETARY REQUIREMENTS --- ")

gluten_free = ask_yes_no("Do you need a Gluten-Free base?")
if gluten_free:
    total_cost = total_cost + 3
    print("Added $3 for Gluten-Free base.")

dairy_free = ask_yes_no("Do you need Dairy-Free cheese?")
if dairy_free:
    total_cost = total_cost + 2
    print("Added $2 for Dairy-Free cheese.")

vegetarian = ask_yes_no("Would you like Vegetarian toppings?")
if vegetarian:
    toppings = "Vegetarian toppings (Mushrooms, Peppers, Olives)"
    print("Vegetarian toppings selected (Mushrooms, Peppers, Olives).")
else:
    toppings = "Classic Meat Supreme toppings"
    print("Classic Meat Supreme toppings selected.")

# ---------- 4. Extensions (fast finishers) ----------

print(" --- EXTRAS --- ")

garlic_bread = ask_yes_no("Would you like a side of Garlic Bread ($4)?")
if garlic_bread:
    total_cost = total_cost + 4
    print("Added $4 for Garlic Bread.")

delivery = ask_choice("Is this for delivery or pickup?", ["delivery", "pickup"]) == "delivery"
if delivery:
    total_cost = total_cost + 5
    print("Added $5 delivery fee.")

# ---------- 5. Final order summary ----------

print(" ------------------------------------ ")
print("Thank you, " + name + "!")
print("Pizza size: " + size.title())

dietary_notes = []
if gluten_free:
    dietary_notes.append("Gluten-Free base")
if dairy_free:
    dietary_notes.append("Dairy-Free cheese")
if dietary_notes:
    print("Dietary notes: " + ", ".join(dietary_notes))
else:
    print("Dietary notes: none")

print("Toppings: " + toppings)
if garlic_bread:
    print("Side: Garlic Bread")
print("Delivery or pickup: " + ("Delivery" if delivery else "Pickup"))
print("Your total for your custom pizza comes to: $" + str(total_cost))
print("====================================")

# ---------- save the order for Shelly the turtle ----------

order = {
    "name": name,
    "size": size,
    "gluten_free": gluten_free,
    "dairy_free": dairy_free,
    "vegetarian": vegetarian,
    "garlic_bread": garlic_bread,
    "delivery": delivery,
    "total_cost": total_cost,
}
with open("last_order.json", "w") as f:
    json.dump(order, f, indent=2)

print("Order saved! Run  python pizza_turtle.py  to watch Shelly draw your pizza.")
