import json, sys, glob
cat = {c['uuid']: c for c in json.load(open('catalogue_my_projects.json'))}
batches = sys.argv[1].split(','); only = set(sys.argv[2:])
for b in batches:
    P = {json.loads(l)['case']: json.loads(l) for l in open(f'review/{b}_in.jsonl') if l.strip()}
    try: V = [json.loads(l) for l in open(f'review/{b}_out.jsonl') if l.strip()]
    except FileNotFoundError: continue
    for v in V:
        if only and v['case'] not in only and v['decision'] not in only: continue
        p = P[v['case']]; r = p['realtycheck']; t = cat.get(v.get('uuid') or '', {})
        cd = next((c for c in p['catalogue_candidates'] if c['uuid'] == v.get('uuid')), {})
        print(f"\n{v['case']} {r['name']} [{r['category']}] n={r['sales_count']} RM{r['median_price_rm']} psf {r['psf']} | {r['page_address'][:80]}")
        if t: print(f"   → {v['decision']} {v['confidence_pct']}%: {t['project_name']} / {t['area']} / {t['property_type']} | psf {t['psf_median']} med {t['price_median']} | {cd.get('dist_m','?')}m {cd.get('why','(outside list)')} | same_sale={bool(cd.get('same_sale_as_realtycheck'))}")
        else: print(f"   → {v['decision']} {v['confidence_pct']}%")
        print(f"   {v['reason'][:300]}")
