#!/usr/bin/env python3
"""Incremental typed reuse checks for all thumbnail-derived descriptions."""
import concurrent.futures,json,sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'lib'))
from visual_safety import cached
import card
state=json.loads((ROOT/'embeddings.json').read_text());descs={x['description'] for x in state['assets'].values()}
with concurrent.futures.ThreadPoolExecutor(max_workers=6) as pool:
    for desc,result in zip(descs,pool.map(lambda d:cached(d,ROOT),descs)):
        if result['blocked']:print('restricted',desc[:120],result['probabilities'],flush=True)
# Explicit opt-outs remain stronger than defaults. Source paintings stay blocked even with blank render textures.
for cid,vs in card.load_all(ROOT).items():
    c=card.active(vs);v=c.get('visual')
    if not v:continue
    risk=cached(v['description'],ROOT);v['safety']=risk
    if risk['blocked'] or c['provenance'].get('third_party_artwork') or c['provenance'].get('person'):
        c['reuse']={'omg':False,'omu':False,'reason':'third-party artwork or person'}
    card.write(ROOT,c)
print('unique descriptions checked',len(descs),'cache files',len(list((ROOT/'safety').glob('*.json'))))
