import type { ResourceSlug, ServiceSlug } from "@/content/types";

export const serviceSlugs: readonly ServiceSlug[] = [
  "paid-media",
  "paid-social",
  "seo-ai-search",
  "cro",
  "landing-pages",
  "analytics-attribution",
  "lifecycle-retention",
] as const;

export const resourceSlugs: readonly ResourceSlug[] = [
  "saas-cac-benchmarking-guide",
  "mer-vs-roas-guide",
  "landing-page-experiment-checklist",
  "paid-search-account-audit-checklist",
  "attribution-readiness-guide",
  "ai-search-visibility-guide",
] as const;

export const routes = {
  home: "/",
  saas: "/saas-marketing",
  ecommerce: "/ecommerce-marketing",
  howWeWork: "/how-we-work",
  about: "/about",
  resources: "/resources",
  audit: "/growth-audit",
  contact: "/contact",
  privacy: "/privacy",
  terms: "/terms",
  cookiePolicy: "/cookie-policy",
  cookiePreferences: "/cookie-preferences",
  service: (slug: ServiceSlug) => `/${slug}`,
  resource: (slug: ResourceSlug) => `/resources/${slug}`,
} as const;

export const staticRoutes = [
  routes.home,
  routes.saas,
  routes.ecommerce,
  routes.howWeWork,
  routes.about,
  routes.resources,
  routes.audit,
  routes.contact,
  routes.privacy,
  routes.terms,
  routes.cookiePolicy,
  routes.cookiePreferences,
] as const;

/** Every indexable path on the site. Used by the sitemap and by link-integrity tests. */
export function getAllRoutes(): string[] {
  return [
    ...staticRoutes,
    ...serviceSlugs.map((slug) => routes.service(slug)),
    ...resourceSlugs.map((slug) => routes.resource(slug)),
  ];
}

/** Home-page anchors that other pages may deep-link to. */
export const homeAnchors = ["revenue-circuit", "growth-diagnostic", "services", "process", "faq"] as const;

/** True when an internal href (path, optional #hash or ?query) points to a real route. */
export function isKnownInternalHref(href: string): boolean {
  if (!href.startsWith("/")) return false;
  const [pathAndQuery, hash] = href.split("#");
  const path = pathAndQuery.split("?")[0] || "/";
  const known = new Set(getAllRoutes());
  if (!known.has(path)) return false;
  if (hash && path === "/") return (homeAnchors as readonly string[]).includes(hash);
  return true;
}
