#!/usr/bin/env python3
"""s38 배경 계보 교체 — 마스터를 s29 top2 최종 수정본으로.

s29_top_v2 최종 산출(45도 항공 전체 부지, 3롤→GPT/Gemini 합산 판정→결함
취합 i2i 수정)=top2_photo_fixed_nb2.png 를 마스터로, s37 에서 LLM 이
저작해 둔 샷별 배경 프롬프트(ext_bg)를 재사용해 실외 8샷 플레이트를
재생성한다. 산출: out/s38/bg2_<tag>.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 s37_rooftop_rebuild as W  # noqa: E402
import s38_lightconti_full as L  # noqa: E402

MASTER = HERE / "out" / "forest_map" / "top2" / "top2_photo_fixed_nb2.png"
assert MASTER.exists(), MASTER

p37 = F.load_plan(W.PLAN)
for tag in p37["ext_tags"]:
    it = p37["ext_bg"][tag]
    out = L.OUT / f"bg2_{tag}.png"
    F.img_nb2(f"s38_bg2_{tag}", it["bg_prompt_en"],
              [(W.MASTER_REF_LABEL, MASTER)], aspect_ratio="16:9",
              out_path=out)
    print("[bg2]", tag)
print("DONE")
