/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      { protocol: "https", hostname: "*.supabase.co" },
      { protocol: "https", hostname: "avatars.githubusercontent.com" },
    ],
  },
};

// Fix 10: Validate required env vars at startup (server-side only, production only)
// This ensures the app fails fast at deploy time rather than crashing mid-request.
if (typeof window === "undefined" && process.env.NODE_ENV === "production") {
  const required = [
    "ENCRYPTION_SECRET",
    "NEXT_PUBLIC_SUPABASE_URL",
    "NEXT_PUBLIC_SUPABASE_ANON_KEY",
    "SUPABASE_SERVICE_ROLE_KEY",
  ];
  const missing = required.filter((key) => !process.env[key]);
  if (missing.length > 0) {
    throw new Error(
      `[PromptMotion] Missing required environment variables: ${missing.join(", ")}\n` +
      `Add them to your .env.local (dev) or Vercel Dashboard > Settings > Environment Variables (production).`
    );
  }
}

export default nextConfig;
