#!/usr/bin/env python3
"""
Generate OG images for the per-competitor comparison pages, using the same
editorial template as generate_og_images.py.

Outputs to public/og-{slug}.png (matches the ogImageSlug values in
resources/js/data/competitors.ts so the existing route -> file convention
keeps working — we only switch the extension from .svg to .png in
Marketing/Comparison.tsx).

Usage:
    python3 scripts/branding/generate_competitor_ogs.py
"""

from __future__ import annotations

from pathlib import Path

import cairosvg

# Reuse the template / palette / crown markup from the main OG generator.
import sys
sys.path.insert(0, str(Path(__file__).resolve().parent))
from generate_og_images import (  # type: ignore
    PUBLIC_DIR,
    build_og_svg,
    preflight_fonts,
)

# slug → display name
COMPETITORS: list[tuple[str, str]] = [
    ("vs-surfer-seo", "Surfer SEO"),
    ("vs-clearscope", "Clearscope"),
    ("vs-rank-math", "Rank Math"),
    ("vs-yoast-seo", "Yoast SEO"),
    ("vs-ahrefs", "Ahrefs"),
    ("vs-semrush", "Semrush"),
    ("vs-marketmuse", "MarketMuse"),
    ("vs-frase", "Frase"),
    ("vs-neuronwriter", "NeuronWriter"),
    ("vs-se-ranking", "SE Ranking"),
    ("vs-mangools", "Mangools"),
    ("vs-writerzen", "WriterZen"),
    ("vs-jasper", "Jasper"),
    ("vs-moz", "Moz"),
    ("vs-ubersuggest", "Ubersuggest"),
    ("vs-serpstat", "Serpstat"),
    ("vs-page-optimizer-pro", "Page Optimizer Pro"),
    ("vs-searchatlas-otto", "SearchAtlas OTTO"),
    ("vs-seotesting", "SEOTesting"),
    ("vs-rankiq", "RankIQ"),
    ("vs-koala-ai", "Koala AI"),
]


def main() -> None:
    preflight_fonts()
    print(f"Generating {len(COMPETITORS)} competitor OG images …")
    for slug, name in COMPETITORS:
        # Headline: "RankWizAI / vs. {Competitor}." — three lines, editorial.
        # Use a forward slash as the separator (mono breadcrumb echo) to keep
        # competitor name on its own line at any length.
        if len(name) > 14:
            # Long competitor names get a 2-line stacked treatment.
            headline = f"RankWizAI\nvs.\n{name}."
        else:
            headline = f"RankWizAI\nvs. {name}."

        svg = build_og_svg(
            slug=f"/compare/{slug.replace('vs-', '')}",
            headline=headline,
            subhead="WordPress-native. Real GSC data. Free to start.",
            eyebrow="Comparison",
        )
        png_path = PUBLIC_DIR / f"og-{slug}.png"
        cairosvg.svg2png(
            bytestring=svg.encode("utf-8"),
            write_to=str(png_path),
            output_width=1200,
            output_height=630,
        )
        print(f"  → og-{slug}.png  {png_path.stat().st_size/1024:.1f} KB")
    print("Done.")


if __name__ == "__main__":
    main()
