/**
 * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
 * for Docker builds.
 */
import "./src/env.js";

/** @type {import("next").NextConfig} */
const config = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**',
      },
      {
        protocol: 'http',
        hostname: '**',
      },
    ],
  },
  // Allow cross-origin requests from local network in dev mode
  // Note: In Next.js 16, we disable this check entirely for dev
  async headers() {
    return [
      {
        source: '/:path*',
        headers: [
          { key: 'Access-Control-Allow-Origin', value: '*' },
          { key: 'Access-Control-Allow-Methods', value: 'GET,POST,PUT,DELETE,OPTIONS' },
          { key: 'Access-Control-Allow-Headers', value: 'Content-Type, Authorization' },
        ],
      },
    ];
  },

  turbopack: {
    // Disable Turbopack and use Webpack instead for compatibility
    // This is necessary for server-side code that uses child_process
  },
  webpack: (config, { dev, isServer }) => {
    if (dev && !isServer) {
      config.watchOptions = {
        poll: 1000,
        aggregateTimeout: 300,
      };
    }
    // Handle server-side modules
    if (isServer) {
      config.externals = config.externals || [];
      if (!config.externals.includes('child_process')) {
        config.externals.push('child_process');
      }
    }
    return config;
  },
  // TypeScript errors will fail the build
  typescript: {
    ignoreBuildErrors: false,
  },
};

export default config;
