import type { MetadataRoute } from "next";
import { SITE_URL } from "@/lib/seo/site";

/** صفحات خاصة/معاملات لا فائدة من زحفها (حساب، دخول، دفع) */
const PRIVATE_PATHS = [
    "/profile",
    "/login",
    "/otp-code",
    "/forget-password",
    "/reset-password",
    "/courses/payment/",
    "/training-courses/*/payment",
    "/offers/*/payment",
    "/bot",
];

/**
 * زواحف محركات البحث ومساعدات الذكاء الاصطناعي مسموح لها صراحةً.
 * ملاحظة: الزاحف الذي يطابق مجموعة باسمه يتجاهل مجموعة "*" تماماً،
 * لذلك تُكرَّر قائمة المسارات الخاصة في كل مجموعة.
 */
const SEARCH_AND_AI_BOTS = [
    // محركات البحث
    "Googlebot",
    "Googlebot-Image",
    "Bingbot",
    "DuckDuckBot",
    "YandexBot",
    "Applebot",
    // البحث والإجابة بالذكاء الاصطناعي
    "GPTBot", // OpenAI
    "OAI-SearchBot", // ChatGPT Search
    "ChatGPT-User",
    "PerplexityBot",
    "Perplexity-User",
    "ClaudeBot", // Anthropic
    "Claude-SearchBot",
    "Claude-User",
    "Google-Extended", // Gemini
    "Applebot-Extended",
    "Amazonbot",
    "Meta-ExternalAgent",
    "CCBot", // Common Crawl (مصدر بيانات لعدة نماذج)
];

/** يحلّ محل robots.txt الثابت في المشروع الأصلي (الذي كان يسمح بكل شيء) */
export default function robots(): MetadataRoute.Robots {
    return {
        rules: [
            { userAgent: SEARCH_AND_AI_BOTS, allow: "/", disallow: PRIVATE_PATHS },
            { userAgent: "*", allow: "/", disallow: PRIVATE_PATHS },
        ],
        sitemap: `${SITE_URL}/sitemap.xml`,
        host: SITE_URL,
    };
}
