import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  transpilePackages: ['@innungsapp/shared'],
  output: process.env.DOCKER_BUILD ? 'standalone' : undefined,
  experimental: {},
  // Include Prisma binaries in standalone build
  outputFileTracingIncludes: {
    '/': [
      './node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/.prisma/**/*',
      './node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/@prisma/client/**/*',
    ],
  },
  webpack: (config, { dev }) => {
    if (dev) {
      // Avoid filesystem cache writes on very low-disk dev machines (ENOSPC).
      config.cache = false
    }
    return config
  },
  // Serve uploaded files
  async rewrites() {
    return [
      {
        source: '/uploads/:path*',
        destination: '/api/uploads/:path*',
      },
    ]
  },
}

export default nextConfig
