#!/usr/bin/env python3
"""Hero piloto 06 — ANGULO E — TERCEIRIZACAO.

Conceito (opcao A preferida pelo Renato):
- UM fotografo autonomo (dono da operacao), sozinho no comando.
- Meio-corpo, 3/4 virado pra esquerda OLHANDO pro notebook.
- Expressao calma + confiante (nao exausto, nao euforico — profissional satisfeito).
- Notebook aberto com GRID de fotos de evento sendo processado automaticamente.
- Fundo: home studio / escritorio pequeno de autonomo (NAO corporativo frio).
- Luz direcional natural (dia, janela aberta) — "trabalho em curso" nao "fim de dia".
- NENHUM sinal de equipe externa: sem outras pessoas, sem multiplos computadores,
  sem pilha de HDs, sem documentos de servico contratado.
- Narrativa visual: "ele sozinho + Cloud PhotoRF 2.0 = producao completa".

REGRAS PX3 (CRITICO):
- ZERO numeros/metricas na cena.
- Fotorrealista, nunca vetor/silhueta.
- Grid de fotos VISIVEL e identificavel como fotos de PESSOAS reais.
- Luz NATURAL de dia (nao golden hour — isso ja foi usado no angulo D).
"""
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 three-quarter portrait of a self-employed Brazilian photographer in his 30s, "
    "seated at his wooden desk inside a small home photography studio, body turned three-quarters to the left, "
    "clearly looking DOWN AND TO THE LEFT at his open laptop screen, "
    "calm confident focused expression — professional satisfaction, NOT tired, NOT stressed, NOT euphoric, "
    "wearing a casual neutral dark t-shirt or henley, hands relaxed near the laptop keyboard, one hand lightly resting on the trackpad, "
    "the modern laptop sits open on the wooden desk in the LEFT portion of the frame and prominently displays a 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, "
    "NATURAL DIFFUSED DAYLIGHT streaming in from a window on the left side of the room, bright productive midday light, soft shadows, NOT golden hour, NOT sunset, this is clearly work in progress during the day, "
    "visible background behind the photographer: cozy indie home studio of a solo freelancer, a single DSLR camera resting on a shelf softly out of focus, one or two small framed photo prints on the warm-painted wall, a small plant, warm wood tones, "
    "ABSOLUTELY NO other people visible, NO second computer, NO extra monitors beyond the one laptop, NO stacks of external hard drives, NO printed contracts or outsourcing paperwork, NO office cubicles, NO corporate environment, NO team meeting background — the photographer is COMPLETELY ALONE in his small personal workspace, "
    "the narrative mood is QUIET CONTROL and OWNERSHIP — one person running his entire operation by himself, in command, no outsourcing needed, "
    "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 natural warm daylight, wood tones and skin tones, "
    "shot on 50mm lens at f/2.8, shallow depth of field, sharp focus on the photographer's face in the right third of the frame and the laptop screen in the left third of the frame, both clearly in frame, "
    "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, subject offset to the right side and laptop prominent on the left side"
)

print("Gerando hero E (terceirizacao / dono-sozinho) 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_terceirizacao_E.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
