import type { MetadataRoute } from "next";
import { BRAND_DOMAIN } from "@/lib/brand";
import { loadRealisations } from "@/lib/realisations-server";

const BASE_URL = `https://${BRAND_DOMAIN}`;

export default function sitemap(): MetadataRoute.Sitemap {
  const lastModified = new Date();
  const routes: { path: string; priority: number; changeFrequency: MetadataRoute.Sitemap[number]["changeFrequency"] }[] = [
    { path: "", priority: 1.0, changeFrequency: "weekly" },
    { path: "/essentiel", priority: 0.9, changeFrequency: "monthly" },
    { path: "/tarifs", priority: 0.9, changeFrequency: "monthly" },
    { path: "/realisations", priority: 0.85, changeFrequency: "monthly" },
    { path: "/expertises/site-internet", priority: 0.8, changeFrequency: "monthly" },
    { path: "/expertises/seo-geo", priority: 0.8, changeFrequency: "monthly" },
    { path: "/expertises/e-commerce", priority: 0.8, changeFrequency: "monthly" },
    { path: "/contact", priority: 0.7, changeFrequency: "monthly" },
    { path: "/mentions-legales", priority: 0.2, changeFrequency: "yearly" },
    { path: "/cgv", priority: 0.2, changeFrequency: "yearly" },
    { path: "/confidentialite", priority: 0.3, changeFrequency: "yearly" },
    ...loadRealisations().map((r) => ({
      path: `/realisations/${r.slug}`,
      priority: 0.7,
      changeFrequency: "monthly" as const,
    })),
  ];

  return routes.map(({ path, priority, changeFrequency }) => ({
    url: `${BASE_URL}${path}`,
    lastModified,
    changeFrequency,
    priority,
  }));
}
