"""
AI Room Designer — step-by-step plan + CAD budget engine (Stage 2).

Generates a plan FROM the actual redesign job: mode + room type + the mode's
change clause drive the steps, and every step carries priced line items in CAD
(ranges from a small in-code 2026 GTA retail/labour table — big-box mid-range,
not luxury, not bargain-bin). Totals are summed per step and for the plan.

This is deliberately deterministic: same mode + room = same plan structure, so
plans are reviewable and testable. When a live room-analysis model is wired in,
it will only swap the item quantities, not the shape.
"""
import json

# Room-specific anchors used to make steps concrete, not generic.
ROOM_ANCHORS = {
    "kitchen": {"hero": "cabinetry and counters", "surface": "cabinet fronts",
                "soft": "stool cushions and a runner", "light": "under-cabinet and pendant lighting"},
    "living": {"hero": "sofa and media wall", "surface": "walls",
               "soft": "cushions, throws and the rug", "light": "floor and table lamps"},
    "bedroom": {"hero": "bed and headboard wall", "surface": "walls",
                "soft": "bedding, cushions and a rug", "light": "bedside lamps and a pendant"},
    "room": {"hero": "main furniture grouping", "surface": "walls",
             "soft": "cushions, throws and the rug", "light": "lamps and ceiling light"},
}

# Each mode: ordered steps. Item = (name, qty, low CAD, high CAD).
MODE_PLANS = {
    "complete-transformation": [
        ("Clear & prep", [("Room clear-out and surface prep (labour)", 1, 150, 300),
                          ("Wall repair and primer", 1, 90, 180)]),
        ("Paint the shell", [("Premium interior paint, walls + ceiling", 1, 220, 420),
                             ("Painter labour (or DIY $0)", 1, 0, 600)]),
        ("Replace the {hero}", [("New hero furniture piece(s)", 1, 1200, 3200),
                                ("Secondary furniture piece", 1, 500, 1400)]),
        ("New lighting scheme", [("Statement fixture for {light}", 1, 250, 750),
                                 ("Bulbs, dimmers and switches", 1, 80, 200)]),
        ("Textiles & soft layers", [("Curtains / window treatment", 1, 180, 520),
                                    ("{soft} set", 1, 200, 550)]),
        ("Decor & styling", [("Wall art and mirror", 1, 150, 450),
                             ("Plants and styling objects", 1, 100, 300)]),
        ("Final fit & finish", [("Delivery and assembly", 1, 150, 400),
                                ("Touch-up kit and final clean", 1, 60, 120)]),
    ],
    "look-more-expensive": [
        ("Declutter & deep clean", [("Editing/declutter session (labour)", 1, 0, 200),
                                    ("Storage baskets and organisers", 1, 60, 150)]),
        ("Upgrade the {surface}", [("Premium finish upgrade for {surface}", 1, 600, 1800),
                                   ("Hardware swap — brass/matte-black pulls and handles", 1, 120, 350)]),
        ("Layer the lighting", [("Added light source for {light}", 1, 200, 650),
                                ("Warm 2700K bulbs throughout", 1, 40, 90)]),
        ("Richer textiles", [("Upgrade {soft} to velvet/linen", 1, 250, 700),
                            ("Full-length curtains, hung high", 1, 200, 550)]),
        ("One statement piece", [("Statement decor piece (mirror, art or sculpture)", 1, 250, 900)]),
        ("Style & photograph", [("Styling session — surfaces, books, greenery", 1, 80, 250)]),
    ],
    "pinterest-mode": [
        ("Lock the colour story", [("Paint — one cohesive palette, walls", 1, 180, 380),
                                   ("Sample pots and swatch testing", 1, 30, 60)]),
        ("Style the {surface}", [("Styled shelving/surface decor set", 1, 200, 550),
                                 ("Matching storage baskets and trays", 1, 80, 220)]),
        ("Layer textiles", [("Layered {soft} in the palette", 1, 220, 600),
                            ("Curtains — soft, floor-length", 1, 180, 480)]),
        ("Greenery", [("Plants — 3 sizes, with pots", 1, 120, 320)]),
        ("Art & focal wall", [("Gallery art set / large print with frame", 1, 150, 450)]),
        ("Warm the light", [("Warm bulbs + one accent lamp for {light}", 1, 120, 350)]),
    ],
    "budget-refresh": [
        ("Declutter & rearrange", [("Declutter session (labour — DIY $0)", 1, 0, 0),
                                   ("Storage bins and donation bags", 1, 25, 60)]),
        ("Repaint", [("One fresh wall colour — paint + supplies", 1, 120, 260)]),
        ("Cheap soft touches", [("New cushion covers (set of 4)", 1, 50, 110),
                                ("Throw blanket", 1, 30, 70),
                                ("Budget rug", 1, 90, 220)]),
        ("Greenery & art", [("Two easy-care plants with pots", 1, 40, 90),
                            ("Printable art + budget frames (set of 3)", 1, 35, 85)]),
        ("Light lift", [("Warm LED bulbs throughout", 1, 25, 55)]),
    ],
    "fix-my-layout": [
        ("Measure & map", [("Tape measure + painter's tape for layout marking", 1, 15, 35)]),
        ("Move the {hero}", [("Furniture sliders and moving straps", 1, 25, 60),
                             ("Two-person moving help (labour, 2h)", 1, 0, 160)]),
        ("Fix the walkways", [("Rug repositioning / right-size rug if needed", 1, 0, 240)]),
        ("Cable & clutter control", [("Cable management kit", 1, 25, 70),
                                     ("One storage piece only if a gap remains", 1, 0, 250)]),
        ("Re-anchor the lighting", [("Move/re-aim {light} to the new grouping", 1, 0, 120)]),
        ("Live with it a week", [("No purchase — adjustment session", 1, 0, 0)]),
    ],
    "colors-and-lighting": [
        ("Pick the palette", [("Sample pots (3 colours) + swatch boards", 1, 30, 65)]),
        ("Repaint the {surface}", [("Premium paint — walls", 1, 200, 400),
                                   ("Rollers, tape and drop cloths", 1, 45, 90),
                                   ("Painter labour (or DIY $0)", 1, 0, 550)]),
        ("Layer the light", [("Second light source — {light}", 1, 120, 380),
                             ("Dimmer switch + install", 1, 60, 160)]),
        ("Warm bulbs throughout", [("2700K LED bulbs, full room set", 1, 40, 95)]),
        ("Tie it together", [("Two accents in the new palette ({soft})", 1, 60, 180)]),
    ],
}


def build_plan(mode_key, room="room"):
    anchors = ROOM_ANCHORS.get(room, ROOM_ANCHORS["room"])
    steps, total_low, total_high = [], 0, 0
    for i, (title, items) in enumerate(MODE_PLANS[mode_key], start=1):
        priced = []
        s_low = s_high = 0
        for name, qty, low, high in items:
            name = name.format(**anchors)
            priced.append({"item": name, "qty": qty,
                           "cad_low": low * qty, "cad_high": high * qty})
            s_low += low * qty
            s_high += high * qty
        steps.append({"step": i, "title": title.format(**anchors),
                      "items": priced, "cad_low": s_low, "cad_high": s_high})
        total_low += s_low
        total_high += s_high
    return {"mode": mode_key, "room": room, "currency": "CAD",
            "steps": steps, "total_cad_low": total_low, "total_cad_high": total_high,
            "note": "Concept-render plan. Prices are mid-range GTA retail/labour "
                    "ranges (2026) to confirm at purchase; measure before buying."}


if __name__ == "__main__":
    import sys
    print(json.dumps(build_plan(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else "room"), indent=2))
