#!/usr/bin/env python3
"""Hero piloto 04 v2 — CURIOSIDADE — VERSAO VERTICAL para 9:16 (story/reels).

Mesmo conceito do hero_curiosidade_v2 (notebook com grid 4x4 de fotos de
formandos + mao humana ao lado), mas em formato portrait (1024x1536)
para encaixar melhor no story 1080x1920.
"""
import os
import base64
from pathlib import Path

env_path = Path("/opt/mia/.env")
for line in env_path.read_text().splitlines():
    if line.startswith("OPENAI_API_KEY="):
        os.environ["OPENAI_API_KEY"] = line.split("=", 1)[1].strip()
        break

try:
    from openai import OpenAI
except ImportError:
    os.system("pip install --break-system-packages openai -q")
    from openai import OpenAI

client = OpenAI()
OUT = Path("/opt/mia/workspace/clientes/px3lab/lancamento_photorf2/criativos_oferta")

prompt = (
    "Photorealistic cinematic vertical portrait shot of an open modern MacBook laptop viewed from above-front at a slight three-quarter angle, "
    "the laptop screen prominently displays a clear visible grid of 16 real portrait photos arranged in a 4x4 gallery layout, "
    "the photos show young people wearing graduation gowns and formal attire smiling at a graduation ceremony, "
    "each thumbnail is clearly a recognizable human face photograph with natural warm skin tones, colored clothing, and real event backgrounds, "
    "the photos look like typical professional event photography thumbnails in a photo management app, "
    "the keyboard of the laptop is partially visible in the lower frame with soft key reflections, "
    "the laptop sits on a dark wooden desk, "
    "cinematic soft dramatic side lighting from the upper left, "
    "very subtle lime-green glow (hex #87C925) coming only from a thin accent line on the screen edge, discreet, not dominating, "
    "the overall color palette is natural warm tones of the photos themselves, "
    "a relaxed adult human hand rests completely still on the wooden desk to the right of the laptop, palm down, fingers relaxed, NOT touching the keyboard, NOT clicking, just observing, "
    "the hand has natural skin tone, lit by soft ambient light, visible and clearly identifiable as a human hand, "
    "deep dark background with soft bokeh and subtle texture at the top and bottom of the frame, not pure black, "
    "atmosphere: calm productive tech, mysterious but inviting, as if the computer is organizing the photos by itself while the person just watches, "
    "shot on 50mm lens, shallow depth of field with sharp focus on the laptop screen showing the photos clearly, "
    "editorial technology photography, hyper detailed, 8k, photorealistic, "
    "no text, no readable logos on the screen, no watermarks, no visible laptop brand, "
    "vertical portrait 2:3 composition, extra dark space above and below the laptop for text overlay"
)

print("Gerando hero curiosidade v2 VERTICAL via gpt-image-1 (20-40s)...")
r = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    size="1024x1536",
    quality="high",
    n=1,
)
b64 = r.data[0].b64_json
dest = OUT / "hero_curiosidade_v2_vertical.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
