import type { MetadataRoute } from "next";
import { SITE_URL } from "@/lib/seo";
import { getAllBolumSlugs, getAllUniversiteSlugs } from "@/lib/katalog";
import { getAllRehberler } from "@/lib/rehber";

// Bilinçli olarak sitemap DIŞI: /sonuc (noindex), /giris, /listem,
// /odeme/sonuc, /rapor/yazdir (auth/utility sayfaları).
const staticEntries: MetadataRoute.Sitemap = [
  { url: `${SITE_URL}/`, priority: 1, changeFrequency: "weekly" },
  { url: `${SITE_URL}/bolumler`, priority: 0.8, changeFrequency: "weekly" },
  { url: `${SITE_URL}/universiteler`, priority: 0.8, changeFrequency: "weekly" },
  { url: `${SITE_URL}/rehber`, priority: 0.8, changeFrequency: "weekly" },
  { url: `${SITE_URL}/paket`, priority: 0.7, changeFrequency: "monthly" },
  { url: `${SITE_URL}/meraklisina`, priority: 0.6, changeFrequency: "monthly" },
  { url: `${SITE_URL}/iletisim`, priority: 0.3, changeFrequency: "yearly" },
  { url: `${SITE_URL}/gizlilik`, priority: 0.2, changeFrequency: "yearly" },
  { url: `${SITE_URL}/kosullar`, priority: 0.2, changeFrequency: "yearly" },
];

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const bolumler: MetadataRoute.Sitemap = getAllBolumSlugs().map((slug) => ({
    url: `${SITE_URL}/bolum/${slug}`,
    priority: 0.7,
    changeFrequency: "monthly",
  }));
  const universiteler: MetadataRoute.Sitemap = getAllUniversiteSlugs().map(
    (slug) => ({
      url: `${SITE_URL}/universite/${slug}`,
      priority: 0.6,
      changeFrequency: "monthly",
    }),
  );
  const rehberler: MetadataRoute.Sitemap = getAllRehberler().map((y) => ({
    url: `${SITE_URL}/rehber/${y.slug}`,
    lastModified: y.tarih,
    priority: 0.7,
    changeFrequency: "monthly",
  }));
  return [...staticEntries, ...bolumler, ...universiteler, ...rehberler];
}
