#!/usr/bin/env python3
"""Hero piloto 05 D VERTICAL v3 (1024x1536) - MESMO angulo do 4:5 aprovado.

Correcao do v2: no v2 o fotografo esta frontal pra camera. O Renato aprovou o 4:5
onde o fotografo esta em 3/4 OLHANDO PRO LAPTOP (nao pra camera), interagindo
com o produto, cafe na MAO DIREITA. Esse eh o angulo correto.

Enquadramento alvo:
- Fotografo em 3/4, virado para a esquerda
- OLHANDO PARA BAIXO, pro laptop (NAO pra camera)
- Sorriso natural ao ver o resultado na tela
- Cafe na MAO DIREITA
- Laptop prominente na mesa a esquerda, grid de formandos visivel
- Luz dourada entrando pela janela esquerda
- Full head and torso visible, headroom no topo
"""
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 editorial photograph (9:16 portrait) of a relaxed professional photographer in his 30s or 40s, "
    "wearing a casual dark t-shirt, in his home photography studio during late golden hour, "
    "CRITICAL POSE: THREE-QUARTER VIEW turned to his LEFT, LOOKING DOWN at his OPEN LAPTOP SCREEN on the wooden desk, NOT facing the camera, NOT making eye contact with the camera, "
    "his gaze is directed downward and to the left toward the laptop screen, natural genuine warm subtle smile on his face as he observes the screen content, "
    "he is interacting with the product, satisfied watching the software do the work for him, "
    "holding a warm ceramic coffee mug in his RIGHT HAND near chest level, "
    "the open modern laptop sits prominently on the wooden desk IN FRONT OF HIM AND TO HIS LEFT, screen clearly visible to the camera, displaying a bright grid of real portrait photographs arranged in a 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 and real event backgrounds, "
    "the photos look like typical professional event photography thumbnails being auto-organized in a photo management app, "
    "FULL HEAD AND TORSO VISIBLE IN FRAME: camera positioned far enough back to show the ENTIRE FACE from the TOP OF THE HEAD (with generous headroom above the hair) down to the mid-chest and the laptop on the desk below, subject centered with the TOP OF THE HEAD clearly inside the frame NOT cropped, "
    "GOLDEN HOUR WARM SUNLIGHT streams in from a large window on the LEFT side behind and beside the photographer, casting warm orange and amber tones across the scene, soft rim light on the photographer's hair and the right side of his face, 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, "
    "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, "
    "VERTICAL MEDIUM SHOT framing: approximately 12-15% headroom above the top of the head, then full face in three-quarter profile visible, then torso down to the chest, then laptop and desk visible in the lower-middle of the frame, "
    "editorial lifestyle technology photography, hyper detailed, 8k, photorealistic, "
    "NO clocks, NO digital numbers, NO watches, NO timestamps, NO text overlays, no readable logos on the screen, no watermarks, no visible laptop brand, "
    "vertical 9:16 composition, cinematic depth, full scene fills the frame edge-to-edge, "
    "ABSOLUTELY CRITICAL CONSTRAINTS: the photographer must NOT be looking at the camera, his face must be in THREE-QUARTER view turned LEFT with eyes directed DOWNWARD at the laptop screen, "
    "the coffee mug must be in his RIGHT HAND, "
    "do NOT crop the top of the head, the top of the hair must be clearly inside the frame with empty space above it"
)

print("Gerando hero D VERTICAL v3 (3/4 olhando pro laptop) via gpt-image-1 (30-60s)...")
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_tempo_D_vertical_v3.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
