"""S12 라인아트 이미지 2장 생성 (Nano Banana 2 = gemini-3.1-flash-image-preview)."""
import sys
from pathlib import Path

BACKEND = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(BACKEND))

from app.modules.llm.gemini_image_client import GeminiImageClient  # noqa: E402

OUTPUT_DIR = BACKEND / "scripts" / "output" / "line_art_s12"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

SHOT_1 = """Pure line drawing on black background, flat 2D diagram style like an architectural blueprint fused with storyboard sketch, with background architecture in thin gray wall lines and thin white furniture lines only. Show the small bedroom from inside the room at curtain level, using a slightly eye-level medium-wide perspective. Parted curtains hang in the extreme near foreground on both left and right edges like torn drapes framing the scene. The bed is drawn in thin white lines along the right wall, its mattress edge and head-side orientation clearly readable, with visible wall space above and behind it to establish the room. Character 1 in cyan stands just beyond the opened curtains in the left-midframe, full body visible as a colored outline silhouette with joint dots, frozen upright after pulling the curtain apart, torso angled three-quarter left, head and gaze directed sharply down and across the room toward the corpse. [FIXED CORPSE POSE — IDENTICAL IN BOTH SHOTS] Character 2 in magenta sits slumped on the floor near the bed and wall in the right-midground, her head bowed down lifelessly. Her shoulder and collarbone are severely mutilated with torn contour damage, resembling jagged bite wounds, with dark red dotted blood flowing from the wounds. A red tattoo mark is visible on her left wrist, and one of her lifeless hands loosely holds a crumpled photograph drawn as a small orange geometric outline. Both her arms hang limply along her torso, her posture completely motionless. [END FIXED POSE] Draw thick blood pools and smeared footprints as red dots and dotted trails across the floor, beginning in the lower foreground and leading diagonally toward character 2, so the eye follows the discovery path. The camera should align character 1 and character 2 on one discovery axis, trapping both figures in the same glance. Keep all shapes as colored vector lines only, no fill, no shading, no texture, and no photorealism. This is the wider first shot of a continuous two-shot sequence, establishing the room layout. Colors: cyan #00E5FF character outlines, magenta #FF00FF character outlines, orange #FFA500 key prop outlines, red #FF0000 blood and marks, white #FFFFFF furniture lines, gray #888888 wall and floor lines, pure black background."""

SHOT_2 = """Pure line drawing on black background, flat 2D diagram style like an architectural blueprint fused with storyboard sketch, preserving the exact same bedroom layout from the previous shot with the bed against the right wall, the curtain area off to the left background, and the same blood trail on the floor. Use a canted medium-wide camera from beside the bed, slightly closer than shot 1, tilting the room slightly so the bed line and wall line slant. [FIXED CORPSE POSE — IDENTICAL IN BOTH SHOTS] Character 2 in magenta sits slumped on the floor near the bed and wall in the right-midground, her head bowed down lifelessly. Her shoulder and collarbone are severely mutilated with torn contour damage, resembling jagged bite wounds, with dark red dotted blood flowing from the wounds. A red tattoo mark is visible on her left wrist, and one of her lifeless hands loosely holds a crumpled photograph drawn as a small orange geometric outline. Both her arms hang limply along her torso, her posture completely motionless. [END FIXED POSE] Character 1 in cyan recoils on the left side of frame, upper body leaning backward in three-quarter right orientation, shoulders pulled back, arms tense, mouth implied open by the silhouette, and gaze lifted away from the corpse toward the wall above the bed. On the upper center wall above the bed, draw an incomplete red circular mark made of wet-looking red dotted and brushed line segments, as if an invisible brush is actively painting a ritual circle in real time. Keep enough negative space around the red circle so the wall plane and bed geometry remain legible in thin gray and white lines. Continue the floor blood as red dots and smeared tracks in the same positions established in shot 1, leading back toward the curtain side, to preserve continuity. The canted angle tilts the room slightly while the corpse anchors the lower right and the red circle dominates the upper center. Keep all entities as colored outlines and joint dots only, no fill, no shading, no gradient, and no photorealism. This is the closer second shot in the same continuous scene. Colors: cyan #00E5FF character outlines, magenta #FF00FF character outlines, orange #FFA500 key prop outlines, red #FF0000 blood and marks, white #FFFFFF furniture lines, gray #888888 wall and floor lines, pure black background."""


def main() -> None:
    client = GeminiImageClient()
    client.set_context(step="line_art_experiment", operation_type="line_art_s12")

    shots = [("s12_shot1_line_art.png", SHOT_1), ("s12_shot2_line_art.png", SHOT_2)]
    for fname, prompt in shots:
        print(f"\n→ generating {fname} ({len(prompt)} chars)...")
        try:
            img_bytes, ms = client.generate_image(prompt=prompt, aspect_ratio="16:9")
            if img_bytes:
                out = OUTPUT_DIR / fname
                out.write_bytes(img_bytes)
                print(f"  ✓ saved {out} ({len(img_bytes)} bytes, {ms}ms)")
            else:
                print(f"  ✗ empty response")
        except Exception as exc:
            print(f"  ✗ failed: {exc}")


if __name__ == "__main__":
    main()
