import type { APIRoute } from "astro";

export const GET: APIRoute = ({ url }) => {
  const base = "https://ethigy.com";

  // Rutas principales en español e inglés
  const routes = [
    { path: "/es/", priority: "1.0", changefreq: "monthly" },
    { path: "/es/servicios", priority: "0.8", changefreq: "monthly" },
    { path: "/es/contacto", priority: "0.8", changefreq: "monthly" },
    { path: "/en/", priority: "1.0", changefreq: "monthly" },
    { path: "/en/servicios", priority: "0.8", changefreq: "monthly" },
    { path: "/en/contacto", priority: "0.8", changefreq: "monthly" },
  ];

  const urls = routes.map(
    ({ path, priority, changefreq }) => `
  <url>
    <loc>${base}${path}</loc>
    <changefreq>${changefreq}</changefreq>
    <priority>${priority}</priority>
  </url>`,
  );

  const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls.join("")}
</urlset>`;

  return new Response(xml, {
    headers: {
      "Content-Type": "application/xml",
      "Cache-Control": "public, max-age=3600",
    },
  });
};
