#!/usr/bin/env python3
"""Generate Pipeline Layer LinkedIn quote cards via OpenAI gpt-image-2."""
import base64, json, os, sys, yaml

cfg = yaml.safe_load(open('/root/.hermes/config.yaml'))
api_key = cfg['image_gen']['openai']['api_key']

from openai import OpenAI
client = OpenAI(api_key=api_key)

OUT = '/root/.hermes/cache/linkedin_batch_2026-08-10'

CARDS = [
    ("linkedin_2026-08-10", "The mistake is picking the tool because it's the one you already have open."),
    ("linkedin_2026-08-11", "AI doesn't fix a messy data model. It amplifies whatever is already there."),
    ("linkedin_2026-08-12", "The value shows up differently: fewer dumb questions in the next status meeting."),
    ("linkedin_2026-08-13", "The pitch is thirty percent of the work. The other seventy is mapping who actually decides."),
    ("linkedin_2026-08-14", "Every AI SDR sending thousands of messages a day is training buyers to ignore it faster."),
]

PROMPT_TMPL = """Minimalist typography-only LinkedIn quote card, landscape orientation.
Background: solid deep navy color #0C111D, flat, no gradients, no textures, no imagery, no icons.
Main quote text: bold modern sans-serif font (like Manrope or Inter), weight 700, colored warm amber #E8893A, centered horizontally and vertically, generous padding on all sides, large readable size, spanning up to 3-4 lines.
Below the quote, in smaller white (#EAEEF6) sans-serif text: "Pipeline Layer"
The exact quote text to render, verbatim with no changes: "{quote}"
Clean, professional, high-end B2B brand aesthetic. No other elements. No watermarks."""

for name, quote in CARDS:
    out_path = os.path.join(OUT, f'{name}.png')
    if os.path.exists(out_path):
        print(f'SKIP {name} (exists)')
        continue
    prompt = PROMPT_TMPL.format(quote=quote)
    print(f'Generating {name}...')
    try:
        result = client.images.generate(
            model='gpt-image-2',
            prompt=prompt,
            size='1536x1024',
            quality='high',
        )
        b64 = result.data[0].b64_json
        with open(out_path, 'wb') as f:
            f.write(base64.b64decode(b64))
        print(f'OK {name} -> {out_path} ({os.path.getsize(out_path)} bytes)')
    except Exception as e:
        print(f'FAIL {name}: {e}')
