import type { NextConfig } from "next";

// 301 redirects for routes removed in the 2026 refactor, so old URLs and
// search-engine references don't 404. (Update spec §4.)
const nextConfig: NextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: "https",
        hostname: "res.cloudinary.com",
      },
    ],
  },
  async redirects() {
    const toHome = [
      "/careers",
      "/careers/:path*",
      "/newsroom",
      "/newsletter",
      "/newsletters",
      "/newsletters/:path*",
      "/agents",
      "/agents/:path*",
      "/models",
      "/models/:path*",
      "/status",
      "/buying-guide",
      "/dashboard/:path*",
      "/solutions",
      "/solutions/:path*",
    ].map((source) => ({ source, destination: "/", permanent: true }));

    const toContact = [
      "/pricing",
      "/book-a-call",
      "/book-a-demo",
      "/get-started",
      "/get-started/:path*",
      "/login",
      "/signup",
      "/sign-in",
      "/grievance",
      "/grievance-officer",
    ].map((source) => ({ source, destination: "/contact", permanent: true }));

    return [
      ...toHome,
      ...toContact,
      // Retired industry verticals (the official three are now Healthcare,
      // Automobile and Real Estate) → the industries hub, so old indexed URLs
      // and inbound links don't 404.
      ...[
        "/industries/logistics",
        "/industries/fintech",
        "/industries/insurance",
        "/industries/ecommerce",
        "/industries/e-commerce",
        "/industries/edtech",
        "/industries/ed-tech",
      ].map((source) => ({ source, destination: "/industries", permanent: true })),
      { source: "/case-studies", destination: "/blog", permanent: true },
      { source: "/case-studies/:path*", destination: "/blog", permanent: true },
      { source: "/help", destination: "/contact", permanent: true },
      { source: "/docs", destination: "/contact", permanent: true },
      { source: "/authors", destination: "/author", permanent: true },
      { source: "/authors/:slug", destination: "/author/:slug", permanent: true },
      { source: "/cookie-policy", destination: "/privacy", permanent: true },
      { source: "/returns", destination: "/terms", permanent: true },
      { source: "/return-policy", destination: "/terms", permanent: true },
    ];
  },
};

export default nextConfig;
