import { site } from "./site";
export const marketingPaths = [
  "/",
  "/about",
  "/personal-loan",
  "/business-loan",
  "/foreigner-loan",
  "/payday-loan",
  "/debt-consolidation-plan",
  "/home-renovation-loan",
  "/contact",
  "/quick-apply",
] as const;
export const stubPaths = ["/privacy-policy", "/terms"] as const;
export const applicationPaths = ["/apply", "/apply-now"] as const;
const aliases: Record<string, string> = {
  "/homepage": "/",
  "/about-us": "/about",
  "/contact-us": "/contact",
  "/personal-loan-old": "/personal-loan",
  "/max-credit-logo_800px_blue": "/images/Max-Credit-Logo_800px_blue.webp",
  ...Object.fromEntries(
    applicationPaths.map((path) => [path, site.application]),
  ),
};
export const retiredPaths = [
  "/hello-world",
  "/sample-page",
  "/features",
  "/plans",
  "/shop",
  "/cart",
  "/checkout",
  "/my-account",
  "/category/uncategorized",
  "/author/admin",
  "/lost-password",
] as const;
export const redirectMap = [
  ...Object.entries(aliases).flatMap(([source, destination]) =>
    [source, `${source}/`].map((source) => ({
      source,
      destination,
      statusCode: 301 as const,
    })),
  ),
  ...[...marketingPaths, ...stubPaths]
    .filter((path) => path !== "/")
    .map((destination) => ({
      source: `${destination}/`,
      destination,
      statusCode: 301 as const,
    })),
];
export function disposition(path: string) {
  const redirect = redirectMap.find((row) => row.source === path);
  if (redirect) return { status: 301, destination: redirect.destination };
  if (
    retiredPaths.some((retired) => path === retired || path === `${retired}/`)
  )
    return { status: 410, destination: null };
  if ([...marketingPaths, ...stubPaths].some((route) => route === path))
    return { status: 200, destination: path };
  return { status: 404, destination: null };
}
