import type { MetadataRoute } from "next";
import { RESOURCE_POSTS } from "@/lib/resources-posts";

const CORE: { route: string; freq: "weekly" | "monthly" | "yearly"; priority: number }[] = [
  { route: "/", freq: "weekly", priority: 1 },
  { route: "/manufacturing-erp", freq: "weekly", priority: 0.9 },
  { route: "/construction-erp", freq: "weekly", priority: 0.9 },
  { route: "/modules", freq: "monthly", priority: 0.8 },
  { route: "/platform", freq: "monthly", priority: 0.8 },
  { route: "/customers", freq: "weekly", priority: 0.8 },
  { route: "/resources", freq: "weekly", priority: 0.8 },
  { route: "/about", freq: "monthly", priority: 0.7 },
  { route: "/request-demo", freq: "monthly", priority: 0.9 },
  { route: "/privacy-policy", freq: "yearly", priority: 0.3 },
  { route: "/terms-of-use", freq: "yearly", priority: 0.3 },
];

export default function sitemap(): MetadataRoute.Sitemap {
  const base =
    process.env.NEXT_PUBLIC_SITE_URL?.replace(/\/$/, "") ||
    "https://www.mxerp.in";
  // NOTE: /thank-you is intentionally excluded (noindex).
  const today = new Date();
  const core = CORE.map((c) => ({
    url: `${base}${c.route}`,
    lastModified: today,
    changeFrequency: c.freq,
    priority: c.priority,
  }));
  const articles = RESOURCE_POSTS.map((p) => ({
    url: `${base}/resources/${p.slug}`,
    lastModified: new Date(p.date + "T00:00:00"),
    changeFrequency: "monthly" as const,
    priority: p.featured ? 0.8 : 0.6,
  }));
  return [...core, ...articles];
}
