import { SUPPORT_KBS, articleHref, categoryHref, kbHref } from '@/lib/support';

// support.afficiency.com/sitemap.xml, as HubSpot serves one today: the home, every KB home, category and article.
export const dynamic = 'force-static';

const ORIGIN = 'https://support.afficiency.com';

export function GET() {
  const paths = ['/'];
  for (const kb of SUPPORT_KBS) {
    paths.push(kbHref(kb));
    for (const c of kb.categories) paths.push(categoryHref(kb, c));
    for (const a of kb.articles) paths.push(articleHref(kb, a));
  }
  const urls = Array.from(new Set(paths)).map((p) => `  <url><loc>${ORIGIN}${encodeURI(p)}</loc></url>`).join('\n');
  const xml = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`;
  return new Response(xml, { headers: { 'Content-Type': 'application/xml; charset=utf-8' } });
}
