#!/usr/bin/env python3
"""Visuels marketing DALL-E pour la fiche produit module Pennylane × PrestaShop."""

from __future__ import annotations

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))

from article_studio.config import load_config
from article_studio.image_gen import generate_featured_image

OUT = ROOT / "exports" / "pennylane-product"

PROMPTS: list[tuple[str, str, str]] = [
    (
        "product-pennylane-featured.png",
        "1792x1024",
        (
            "Professional premium PrestaShop module marketing hero banner, landscape 16:10. "
            "LEFT: white panel, badge MODULE PRESTASHOP, huge headline 'Synchronisation Pennylane', "
            "teal subheadline 'Envoyez vos commandes PrestaShop vers Pennylane automatiquement', "
            "four French feature bullets: création client Pennylane, facture brouillon ou import PDF, "
            "déclenchement par statut commande, journal de synchronisation. "
            "RIGHT: dramatic visual flow diagram PrestaShop order → Pennylane accounting cloud "
            "with glowing sync arrows, invoice document and customer card. "
            "Cinematic premium SaaS marketing, teal and navy blue palette. "
            "French text only. No watermarks."
        ),
    ),
    (
        "product-pennylane-admin-config.png",
        "1792x1024",
        (
            "Ultra-realistic screenshot of PrestaShop 8 admin module configuration page, French UI. "
            "Dark grey left sidebar with Sell/Improve/Configure menu. Main white content: breadcrumb "
            "'Modules > Pennylane > Configuration'. Panel with fields: clé API Pennylane, "
            "toggle Activer la synchronisation, checkboxes statuts de commande déclencheurs, "
            "option factures en brouillon, tableau modèles de facture par boutique multiboutique, "
            "délai de paiement en jours. Buttons 'Tester la connexion API' and blue 'Enregistrer'. "
            "Below: journal Pennylane table with date, niveau, commande, message columns. "
            "Sharp readable text, authentic PrestaShop 8 Symfony back-office, no blur, no watermark."
        ),
    ),
    (
        "product-pennylane-order.png",
        "1792x1024",
        (
            "Ultra-realistic PrestaShop 8 admin order detail page sidebar panel, French interface. "
            "Right sidebar panel titled 'Pennylane' showing sync status badge Succès, "
            "Pennylane customer ID and invoice ID links, button 'Renvoyer vers Pennylane', "
            "link 'Télécharger la facture Pennylane PDF'. Main order view partially visible. "
            "Clean modern Symfony PrestaShop BO design, photorealistic UI screenshot, "
            "crisp typography, teal accent color, no watermark."
        ),
    ),
    (
        "product-pennylane-flow.png",
        "1792x1024",
        (
            "Professional infographic diagram explaining e-commerce accounting sync flow, landscape 16:10, "
            "clean modern SaaS style on white background. Three connected steps left to right with bold arrows: "
            "STEP 1 (orange PrestaShop): Commande validée, changement de statut déclencheur. "
            "STEP 2 (teal): API Pennylane v2, client créé ou retrouvé par référence externe. "
            "STEP 3 (teal): Facture Pennylane brouillon ou import PDF PrestaShop finalisée. "
            "Title in French: Flux de synchronisation PrestaShop × Pennylane. "
            "Colors teal and orange, flat vector infographic, French text only, no watermark."
        ),
    ),
    (
        "product-pennylane-module.png",
        "1024x1024",
        (
            "Square app icon for PrestaShop marketplace module, rounded square with smooth gradient "
            "from deep navy blue to vibrant teal. Center: white sync arrow between a shopping cart "
            "(PrestaShop e-commerce) and a ledger/accounting book (Pennylane), suggesting invoice sync. "
            "Minimal flat modern icon, subtle depth, professional software marketplace quality, "
            "no text, no watermark."
        ),
    ),
]


def main() -> None:
    cfg = load_config()
    api_key = cfg.openai_api_key
    if not api_key:
        raise ValueError("OPENAI_API_KEY requis dans .secrets/.env")

    OUT.mkdir(parents=True, exist_ok=True)
    model = cfg.llm_image_model or "dall-e-3"

    for filename, size, prompt in PROMPTS:
        out_path = OUT / filename
        print(f"Génération {filename} ({size})…")
        generate_featured_image(
            api_key,
            prompt,
            out_path,
            model=model,
            size=size,
        )
        print(f"  → {out_path}")

    print("\nVisuels générés. Lancez package_pennylane.py puis create_wc_product_pennylane.py.")


if __name__ == "__main__":
    main()
