#!/usr/bin/env python3
from pathlib import Path
import sys,json,hashlib,datetime
sys.path.insert(0,'/opt/OpenMontage')
from tools.graphics.cx_image import CXImage
P='gacmai_20260717_104203';R=Path('/data/video-pipeline/GacMaiAudio/project')/P;A=R/'artifacts';O=R/'assets/images/candidates';O.mkdir(parents=True,exist_ok=True)
status=json.loads((R/'status.json').read_text());release=json.loads((A/'story_release_manifest.json').read_text())
if status.get('cx_authorized') is not True or status.get('story_sha256')!=release.get('story_sha256'):raise SystemExit('CX authorization mismatch')
style='premium cinematic illustrated Vietnamese audio drama, semi-realistic polished illustration, dark teal near-black icy blue palette, cream and pale-gold typography, controlled red accents, dramatic key light, controlled rim light, layered atmospheric depth, mature Vietnamese adults, no medical imagery, no waveform, no ECG, no hospital, no watermark, no interface, all props have completely blank unlabeled surfaces, no letters, no numbers, no notation, no pseudo-text except exact requested typography'
prompts={
'intro_v2.png':f'''{style}. 16:9 opening title card for Gác Mái Audio. An archival reel-to-reel tape in a dim preservation room, one tiny missing interval in the tape loop casting a shadow shaped like a Vietnamese communal-house roof, dust in a narrow beam, emotionally restrained, no people. Stylized reel machine has no labels, no meter lettering, no control markings; papers and boxes are blank. Exact readable Vietnamese typography only: "GÁC MÁI AUDIO" and "NỬA NHỊP KHÔNG THUỘC VỀ AI". High-contrast distressed serif title, centered cinematic composition.''',
'left_v2.png':f'''{style}. Vertical 600x1080 left social rail, absolutely zero people and zero faces. Archival paper, reel tape texture and quiet roof-shadow motif, clean safe margins, no papers, no musical notation, no equipment panel, no waveform and no decorative glyphs or separators. Exact readable typography only, stacked: "Gác Mái Audio" "Like" "Share" "Subscribe". Cream-gold distressed serif, no cropped letters.''',
'right_v2.png':f'''{style}. Vertical 600x1080 illustrated poster panel. Protagonist Lê An Nhiên dominant in foreground, Vietnamese female audio-restoration technician in her thirties, focused and morally conflicted, full face visible. Layered supporting cast with five additional mature Vietnamese adults, all faces complete and distinct: Trần Khải Minh, Vũ Thanh Hà, Phạm Đức Long, Đỗ Mai Sương, Hoàng Nhật Quang. Background: sealed archive room with plain blank archive boxes and a stylized unlabeled reel-to-reel silhouette, communal-house roof shadow, no papers, no labels, no equipment markings, no waveform. Exact readable typography only: title "NỬA NHỊP KHÔNG THUỘC VỀ AI" and the six names. No cropped faces, no extra people.'''}
tool=CXImage();items=[]
for name,prompt in prompts.items():
 out=O/name
 if out.exists():raise SystemExit(f'refuse overwrite {out}')
 res=tool.execute({'prompt':prompt,'model':'cx/gpt-5.5-image','size':'1536x864' if name.startswith('intro') else '1024x1536','quality':'high','output_format':'png','n':1,'output_path':str(out)})
 if not res.success or not out.exists():raise RuntimeError(f'{name}: {res.error} {res.data}')
 items.append({'name':name,'path':str(out),'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'bytes':out.stat().st_size})
receipt={'status':'passed','provider':'CXImage','story_sha256':status['story_sha256'],'items':items,'completed_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};(A/'cx_visual_generation_v2_receipt.json').write_text(json.dumps(receipt,indent=2)+'\n');print(json.dumps(receipt))
