#!/usr/bin/env python3
"""Old vs BM25 vs BM25 + word map games_library.pick() on 10 sample briefs + 10 synonym briefs against the current index.json.
Usage: PYTHONPATH=<shim containing forge_corp.api.routes.{games_library,library_search}> python3 integrations/search_wiring_evidence.py
(the shim is the Factory package layout; see REPORT-C.md)."""
import json, sys
from pathlib import Path
from forge_corp.api.routes import games_library as gl

BRIEFS = [
    "a farm with cows and a tractor",
    "haunted house with a wardrobe",
    "pirate harbour",
    "a lantern-lit village with an open pavilion by the sea",
    "cosy campsite by a lake with a tent and a campfire",
    "a lighthouse keeper's cottage with a windmill",
    "a medieval market square with a well and a cart",
    "a supermarket with shelving aisles and trolleys",
    "a school playground with a swing and a slide",
    "stack the pillars and climb the watch tower",
]
SYNONYMS = [
    "a cosy room with a settee and a closet",
    "a harbour with a jetty",
    "lorries on a motorway",
    "a bedsit with a bookcase and a dresser",
    "choppers over the city",
    "a pond with a rowing boat",
    "a seaside lamp post and a fishing boat",
    "a bathroom with a bathtub",
    "a farm with a cow and a dragon",
    "a toaster and a piano in the kitchen",
]
index = json.loads((Path(__file__).resolve().parents[1] / "index.json").read_text())
BRIEFS += [
    "a dragon attacks a village of wolves and orcs",
    "a farm with cows, horses, chickens and a tractor",
    "a forest hunt: deer, a stag, a fox and a hound",
    "an elephant safari with jeeps",
]
wm_path = Path(__file__).resolve().parents[1] / "search" / "word_map.json"
word_map = json.loads(wm_path.read_text()) if wm_path.exists() else None
for b in BRIEFS + SYNONYMS:
    old, oc, og = gl.pick(index, b, semantic=False)
    new, nc, ng = gl.pick(index, b)
    wm, wc, wg = gl.pick(index, b, word_map=word_map)
    oids, nids = [a["id"] for a in old], [a["id"] for a in new]
    print(f"== {b}")
    print(f"   OLD       {len(old):2d} picks  classes={oc}  gaps={og}")
    print(f"             {oids}")
    print(f"   BM25      {len(new):2d} picks  (+{len([i for i in nids if i not in oids])} by words)  added: {[i for i in nids if i not in oids]}")
    print(f"   WORD MAP  {len(wm):2d} picks  (+{len([a for a in wm if a['id'] not in oids])} by words or meaning)  gaps={wg}")
    print(f"             added: {[a['id'] for a in wm if a['id'] not in oids]}")
