#!/usr/bin/env python3
"""임시 실험 6 — 스틸→스틸 자세 체이닝.

S12sh18 실사를 참조=S12sh11 실사(v3 사실화본) 단독으로 생성.
PREV 라벨의 부동 자세 잠금("몸=고정 소품, 카메라만 이동")이 스틸 레벨
에서 손 들어올림 오류를 잡는지 검증. 산출: still_chain_S12sh18.png.
"""
import sys
from pathlib import Path

HERE = Path(__file__).parent
sys.path.insert(0, str(HERE))
import forest_lib as F  # noqa: E402
import s35_fullrun as R  # noqa: E402
import s37_rooftop_rebuild as W  # noqa: E402
import s34_stillrun as S  # noqa: E402

TAG = "S12sh18"
PREV_STILL = W.OUT / "quad3_refined_S12sh11.png"
OUTF = W.OUT / "still_chain_S12sh18.png"

plan = F.load_plan(W.PLAN)
plan35 = W._s35()
mv = W._movement(plan35)
gmap = {g["key"]: g for g in plan35["groups"]}
place_en = gmap[W.INT_GROUP]["place_en"]

s = R.SHOT[R._key(TAG)]
m = mv.get(TAG, {})
fix = plan.get("pose_fix", {}).get(TAG) or {}
movement = fix.get("movement_en") or m.get("movement", "")
figures = fix.get("figures_en") or m.get("figures", "")
carried = fix.get("carried_en") or (plan.get("int_cont", {})
                                    .get(TAG, {}).get("carried_en", ""))
pose_clauses = [
    "IMMOBILE CHARACTER POSE — CANONICAL (on any conflict THIS POSE"
    " WINS): " + S._soften(it["pose_en"])
    for it in plan.get("pose_canon", []) if TAG in it["shots"]]

refs = [(W.PREV_STILL_LABEL, PREV_STILL)]

prompt = "\n\n".join([
    "Create ONE FINAL photorealistic live-action film still of the"
    " moment below — contemporary South Korea, 2026; all people are"
    " Korean unless stated. TIME OF DAY (lock): " + S._time_of(TAG) + ".",
    f"SHOT TEXT (authoritative, Korean): {S._soften(s['desc'])}",
    f"LOCATION (lock): {place_en} The shot takes place here — the"
    " attached PREVIOUS SHOT STILL shows this exact place.",
    "THIS SHOT IS A CLOSER FRAMING OF THE PREVIOUS SHOT: the immobile"
    " woman in the attached still CANNOT MOVE — her body, her hand's"
    " exact resting position on the floor, the crumpled photograph in"
    " that hand, her clothing and every stain stay PRECISELY as in the"
    " attached photograph. Only the camera moves closer. Do NOT lift,"
    " turn, re-pose or re-light her hand or body.",
    "\n".join(pose_clauses) if pose_clauses else "",
    S.REALIZE_STILL,
    ("MOVEMENT (follow exactly): " + S._soften(movement))
    if movement else "",
    ("FIGURES — size & depth (follow exactly): " + S._soften(figures))
    if figures else "",
    ("CARRIED STATE (persist exactly): " + S._soften(carried))
    if carried else "",
    "No text, captions, watermarks or annotations anywhere.",
])

F.img_nb2("x_still_chain_S12sh18", prompt, refs, aspect_ratio="16:9",
          out_path=OUTF)
print("saved:", OUTF)
