import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [react(), tailwindcss()],
  server: {
    proxy: {
      // Proxy grpc-web requests to the tonic-web gateway
      '/auth.AuthService': { target: 'http://localhost:50051' },
      '/trading.TradingService': { target: 'http://localhost:50051' },
      '/risk.RiskService': { target: 'http://localhost:50051' },
      '/ml.MLService': { target: 'http://localhost:50051' },
      '/ml_training.MLTrainingService': { target: 'http://localhost:50051' },
      '/config.ConfigService': { target: 'http://localhost:50051' },
      '/monitoring.MonitoringService': { target: 'http://localhost:50051' },
      '/foxhunt.tli.BacktestingService': { target: 'http://localhost:50051' },
    },
  },
  build: {
    sourcemap: process.env.NODE_ENV !== 'production',
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['react', 'react-dom', 'react-router-dom'],
          charts: ['lightweight-charts', 'recharts'],
          query: ['@tanstack/react-query'],
          grpc: ['@connectrpc/connect', '@connectrpc/connect-web', '@bufbuild/protobuf'],
        },
      },
    },
  },
})
