#!/usr/bin/env python3
"""Attach source sheets through the same importer, preserving handcrafted parts and game pins."""
import json,sys,concurrent.futures
from pathlib import Path
from types import SimpleNamespace
ROOT=Path(__file__).resolve().parents[1];sys.path[:0]=[str(ROOT/'lib'),str(ROOT/'tools')]
import card,ingest_photo_object as imp
base=Path.home()/'forge-build/forge-assets'
jobs=[]
for cid,versions in card.load_all(ROOT).items():
    c=card.active(versions)
    if not cid.startswith('vehicle.space.') or any(t in cid for t in ['trellis2-','pixal3d-']):continue
    source=c['provenance'].get('source','');source=source if isinstance(source,str) else ''
    folder=base/source;photo=folder/'sheet.jpg'
    if not photo.exists():continue
    sha=c['files']['glb'].split(':')[1];thumb=ROOT/'site/out/measure/thumbs'/(sha+'.jpg')
    if not thumb.exists():raise ValueError('missing thumbnail '+str(thumb))
    prov={**c['provenance'],'method':'picture-to-Blender-and-paint','models':[c['provenance'].get('author','Blender author'),'Nano Banana Pro concept sheet','GPT Image 2 paint'],'source':source,'source_picture':str(photo),'date':'2026-10-16','licence_evidence':c['licence']['evidence'],'licence':c['licence']['kind']}
    path=Path('/tmp/wlib-blender-'+cid.split('/')[1]+'.json');path.write_text(json.dumps(prov))
    jobs.append(SimpleNamespace(root=ROOT,glb=ROOT/'store/blobs'/(sha+'.glb'),provenance=path,asset_class=cid.split('/')[0],slug=cid.split('/')[1],name=c['name'],thumbnail=thumb,photo=[photo],metres_per_unit=1,yaw=0,no_reuse=False,existing_id=cid))
# Same-id writes stay serial; the cached thumbnail description avoids new Gemini calls.
for args in jobs:print(imp.ingest(args)['id'],flush=True)
print('Blender sheets attached',len(jobs))
