import { MetadataRoute } from "next";
import { siteConfig } from "@/lib/site";

const SITE_URL = siteConfig.url;

// `/_next/` volontairement ABSENT : le bloquer interdisait à Googlebot le CSS/JS
// (`/_next/static/*`) et surtout `/_next/image` — soit la totalité des images du
// site, donc zéro indexation Google Images. Audit 2026-07-30.
const BLOCKED_PATHS = ["/api/", "/admin/", "/private/"];
const CONTENT_PATHS = [
  "/actualites/",
  "/guides/",
  "/reglementation/",
  "/cas-clients/",
];
// Surface commerciale : sans elle, les moteurs IA ne connaissaient Acieb que via
// son blog — jamais son identité, son offre, ses secteurs ni son contact. Or
// `/llms.txt` (autorisé) pointe justement vers ces pages : le menu était lisible,
// les plats interdits.
const COMMERCIAL_PATHS = [
  "/$", // la home exactement, pas tout le site
  "/contact/",
  "/courtier-en-energie/",
  "/expertise/",
  "/solutions/",
  "/secteurs/",
  "/ressources/",
];
// Découverte : déclarer `Sitemap:` en pied de robots.txt tout en interdisant le
// fichier au même bot était contradictoire.
const DISCOVERY_PATHS = ["/sitemap.xml", "/feed.xml", "/.well-known/"];
const AI_READABLE_PATHS = [
  ...CONTENT_PATHS,
  ...COMMERCIAL_PATHS,
  ...DISCOVERY_PATHS,
  "/outils/",
  "/llms.txt",
  "/llms-full.txt",
  "/services.md",
];

export default function robots(): MetadataRoute.Robots {
  return {
    rules: [
      // Moteurs de recherche + AI search bots + user-triggered fetchers — accès complet
      // ChatGPT-User est déclenché par un humain qui colle une URL : équivalent d'un clic
      {
        userAgent: [
          "Googlebot",
          "Bingbot",
          "PerplexityBot",
          "OAI-SearchBot",
          "ChatGPT-User",
          "YouBot",
          "PhindBot",
        ],
        allow: "/",
        disallow: BLOCKED_PATHS,
      },

      // AI training / citation bots — contenu blog + surface commerciale + discovery
      // Google-Extended gouverne le grounding Gemini et l'entraînement Vertex ; il
      // ne contrôle PAS les AI Overviews, qui s'appuient sur l'index Googlebot.
      {
        userAgent: [
          "GPTBot",
          "ClaudeBot",
          "anthropic-ai",
          "Google-Extended",
        ],
        allow: AI_READABLE_PATHS,
        disallow: ["/", ...BLOCKED_PATHS],
      },

      // Scrapers / training agressif — bloqués
      {
        userAgent: [
          "CCBot",
          "Bytespider",
          "FacebookBot",
          "Meta-ExternalAgent",
          "Applebot-Extended",
          "cohere-ai",
          "Amazonbot",
          "Diffbot",
          "omgili",
        ],
        disallow: "/",
      },

      // Tous les autres
      {
        userAgent: "*",
        allow: "/",
        disallow: BLOCKED_PATHS,
      },
    ],
    sitemap: [
      `${SITE_URL}/sitemap.xml`,
      `${SITE_URL}/feed.xml`,
    ],
  };
}
