#!/usr/bin/env python3
"""Visuels marketing DALL-E pour la fiche produit « brouillons réponse service client »."""

from __future__ import annotations

import sys
import zipfile
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

MODULE_SRC = Path("/Users/arnaudmerigeau/Locals/bohomane_refonte/modules/amsavai")
OUT = ROOT / "exports" / "reponse-service-client-product"

PROMPTS: list[tuple[str, str, str]] = [
    (
        "product-reponse-service-client-featured.png",
        "1792x1024",
        (
            "Professional premium PrestaShop module marketing hero banner, landscape 16:10. "
            "LEFT: white panel, badge MODULE PRESTASHOP, huge headline 'Assistant IA Service Client', "
            "orange subheadline 'Répondez en 10 secondes au lieu de 10 minutes', stat ÷3 temps de traitement, "
            "four French feature bullets about AI, auto context, one-click draft, human control. "
            "RIGHT: dramatic before/after split — AVANT manual 12 min stressed employee vs APRÈS AI 18 sec "
            "with generated draft and glowing Générer la réponse button. Cinematic premium SaaS marketing. "
            "French text only. No Réponse PRO, no watermarks."
        ),
    ),
    (
        "product-reponse-service-client-admin.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 > Réponses service client > Configuration'. Section 'Fournisseur et modèle' with "
            "dropdown OpenAI, fields for API model gpt-4o-mini, temperature 0.4, max tokens. "
            "Section 'Prompt système' with textarea. Toggle switches green ON: inclure commande, "
            "suivi colis, statut transporteur, produit lié. Blue Save button bottom right. "
            "Sharp readable text, authentic PrestaShop 8 Symfony back-office design, studio lighting, "
            "no blur, no watermark."
        ),
    ),
    (
        "product-reponse-service-client-thread.png",
        "1792x1024",
        (
            "Ultra-realistic PrestaShop 8 admin customer service conversation page, French interface. "
            "Header 'SAV > Fil client #12847 — Marie Dupont — Commande #45821'. Top card shows customer "
            "message asking where their parcel is. Bottom card 'Répondre au client' with large textarea "
            "containing a complete professional French reply about Chronopost tracking. "
            "Optional instruction input field. Left-aligned orange button with sparkle icon "
            "'Générer la réponse', right blue 'Envoyer' button. Clean modern Symfony PrestaShop BO, "
            "photorealistic UI screenshot, crisp typography, no watermark."
        ),
    ),
    (
        "product-reponse-service-client-icon.png",
        "1024x1024",
        (
            "Square app icon for PrestaShop module, rounded square with smooth gradient from deep teal "
            "to electric blue. Center: white speech bubble with elegant pen nib or magic sparkle suggesting "
            "draft reply writing. Minimal flat modern icon, subtle depth, professional software marketplace "
            "quality, no text, no watermark."
        ),
    ),
]


def create_zip() -> Path:
    zip_path = OUT / "amsavai-1.0.1.zip"
    with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
        for path in sorted(MODULE_SRC.rglob("*")):
            if path.is_file() and path.name != ".DS_Store":
                zf.write(path, f"amsavai/{path.relative_to(MODULE_SRC).as_posix()}")
    return zip_path


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}")

    zip_path = create_zip()
    print(f"  {zip_path.name} ({zip_path.stat().st_size // 1024} Ko)")


if __name__ == "__main__":
    main()
