#!/usr/bin/env python3
"""Hero piloto 05 — ANGULO D — ECONOMIA DE TEMPO.

Conceito aprovado pelo Renato (opção A):
- UM fotógrafo relaxado, de pé ou sentado em postura calma, braços cruzados
  ou com xícara de café na mão, olhando o notebook com satisfação.
- Notebook aberto mostrando GRID de FOTOS REAIS de pessoas sendo processadas
  automaticamente (grid 4x4 de retratos de evento).
- LUZ DOURADA DE FINAL DE TARDE entrando pela janela ao fundo (narrativa:
  "ainda é hoje, não precisa virar a noite").
- Fundo: estúdio de fotografia profissional casual, ambiente natural.
- Preenchendo bem a cena, sem muito espaço vazio.

REGRAS PX3 (CRÍTICO):
- ZERO números/métricas na cena (sem relógio digital, sem "em X horas").
- Sem face-detection boxes verdes (isso é do ângulo família - já reprovado).
- Fotorrealista, nunca vetor/silhueta.
- Grid de fotos VISÍVEL e identificável como fotos de PESSOAS reais.
"""
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 = (
    "Cinematic photorealistic editorial photograph of a relaxed professional photographer in his 30s or 40s, "
    "wearing a casual dark t-shirt or henley, standing calmly next to a wooden desk inside his home photography studio, "
    "holding a warm ceramic coffee mug in his left hand, right hand relaxed at his side, "
    "his body posture is clearly RELAXED and SATISFIED, slight genuine smile, looking down at an open modern laptop screen with content expression, NOT tired, NOT stressed, "
    "the laptop sits open on the desk and prominently displays a clear visible grid of 16 real portrait photos arranged in a 4x4 gallery layout, "
    "the photos on screen show different 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 being auto-organized in a photo management app, "
    "GOLDEN HOUR WARM SUNLIGHT streams in from a large window behind the photographer on the left side, casting warm orange and amber tones across the scene, soft rim light on the photographer's hair and shoulders, late afternoon golden light flooding the room, "
    "the atmosphere strongly suggests end-of-afternoon calm, warm productive quietness, as if the day is ending early and the work is already done, "
    "visible background: tasteful home photography studio with wooden shelves, a camera on a tripod blurred in the far background, framed photo prints softly out of focus on the wall, warm wood tones everywhere, "
    "the mood is RELIEF and CALM MASTERY — a man enjoying his evening coffee while his software does the heavy work for him, "
    "very subtle lime-green glow (hex #87C925) coming only from a thin accent line on the laptop screen edge, extremely discreet, barely noticeable, not dominating the warm palette, "
    "the dominant palette is warm golden amber from the sunset light and natural human skin tones, "
    "shot on 50mm lens at f/2.8, shallow depth of field with sharp focus on the photographer's face and the laptop screen, both in frame clearly, "
    "editorial lifestyle technology photography, hyper detailed, 8k, photorealistic, "
    "NO clocks, NO digital numbers, NO watches visible, NO timestamps, NO text overlays, no readable logos on the screen, no watermarks, no visible laptop brand, "
    "square 1:1 composition, full scene fills the frame with no empty negative space"
)

print("Gerando hero D (tempo/alívio) via gpt-image-1 (30-50s)...")
r = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    size="1024x1024",
    quality="high",
    n=1,
)
b64 = r.data[0].b64_json
dest = OUT / "hero_tempo_D.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
