#!/usr/bin/env python3
"""reve 2.1 판 — 프로젝트·에피소드 생성 (2026-08-25 사용자 지시).

같은 원고(골목끝 3씬)를 **새 프로젝트**로 올린다. 기존 완주 판
(da049582 / fb7a883f)은 **건드리지 않는다** — 그 판이 기준선이라,
덮으면 「달라진 것」을 잴 대조가 사라진다.

이번 판에서 달라지는 것:
  · 최종 i2i = reve 2.1 (fal queue)      STILL_CINE_PROVIDER=reve
  · 카메라 산문을 앞단에서 걷어 최종 i2i 에  STILL_CINE_STAGE_DIRECTION_ENABLED
  · 최종 산출을 재는 관문                  STILL_CINE_VERIFY_ENABLED

러너가 읽는 state 는 minimal_e2e_state.json 이다 — 옛 판 state 는
minimal_e2e_state.20260824_grok.json 으로 이미 옮겨 뒀다.
"""
import json
from pathlib import Path

import requests

BASE = "http://localhost:8000"
ROOT = Path("/Users/manta/Documents/Projects/TheRoad-I1")
EP_PDF = ROOT / "artifact" / "20260824_minimal_e2e_scenario" / "골목끝.pdf"
STATE = ROOT / "scratchpad" / "minimal_e2e_state.json"
BACKUP = ROOT / "scratchpad" / "minimal_e2e_state.20260824_grok.json"

assert EP_PDF.exists(), f"시나리오 PDF 가 없다: {EP_PDF}"
assert BACKUP.exists(), (
    "옛 판 state 백업이 없다 — 덮기 전에 남겨야 기준선을 잃지 않는다")

s = requests.Session()

r = s.post(f"{BASE}/api/v1/auth/login",
           json={"username": "admin", "password": "admin123"}, timeout=30)
r.raise_for_status()
print("[login] ok", flush=True)

r = s.post(f"{BASE}/api/v1/projects/", json={
    "name": "골목 끝 — reve 2.1 판 20260825",
    "description": "같은 원고를 reve 2.1 최종 i2i + 연출 재료 이동 + 산출 "
                   "관문으로 다시 완주. 대조 기준선 = 골목 끝 최소 검증판 "
                   "20260824(grok 판).",
}, timeout=60)
r.raise_for_status()
pid = r.json()["id"]
print(f"[project] {pid}", flush=True)

with open(EP_PDF, "rb") as f:
    r = s.post(
        f"{BASE}/api/v1/projects/{pid}/episodes/",
        data={"episode_number": "1", "title": "골목 끝"},
        files={"file": (EP_PDF.name, f, "application/pdf")},
        timeout=300,
    )
r.raise_for_status()
ep = r.json()
eid = ep["id"]
print(f"[episode] {eid} · {ep.get('page_count')}쪽 · "
      f"언어 {ep.get('language')}", flush=True)

STATE.write_text(json.dumps({"project_id": pid, "episode_id": eid},
                            ensure_ascii=False))
print(f"[state] {STATE}", flush=True)
