// pages/api/sitemap.js — Optionnel : sitemap dynamique via Next.js
// Le fichier sitemap.xml statique dans /public/ suffit pour la plupart des cas.
// Ce fichier permet de le régénérer dynamiquement si nécessaire.

export default function handler(req, res) {
  const baseUrl = 'https://www.alfredmajor.com';
  const today = new Date().toISOString().split('T')[0];

  const pages = [
    { url: '/', priority: '1.0', changefreq: 'weekly' },
    { url: '/pricing', priority: '0.8', changefreq: 'monthly' },
    { url: '/register', priority: '0.8', changefreq: 'monthly' },
    { url: '/login', priority: '0.5', changefreq: 'monthly' },
    { url: '/conditions-generales', priority: '0.3', changefreq: 'yearly' },
    { url: '/confidentialite', priority: '0.3', changefreq: 'yearly' },
    { url: '/mentions-legales', priority: '0.3', changefreq: 'yearly' },
  ];

  const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/0.9">
${pages.map(p => `  <url>
    <loc>${baseUrl}${p.url}</loc>
    <lastmod>${today}</lastmod>
    <changefreq>${p.changefreq}</changefreq>
    <priority>${p.priority}</priority>
  </url>`).join('\n')}
</urlset>`;

  res.setHeader('Content-Type', 'application/xml');
  res.setHeader('Cache-Control', 'public, max-age=86400, stale-while-revalidate=3600');
  res.status(200).send(xml);
}
