import 'dotenv/config';

export const config = {
  // Server
  port: parseInt(process.env.PORT || '3000', 10),
  nodeEnv: process.env.NODE_ENV || 'development',
  isDev: process.env.NODE_ENV !== 'production',

  // CORS
  corsOrigins: process.env.CORS_ORIGINS?.split(',') || ['http://localhost:5173', 'http://localhost:5174'],

  // Redis
  redis: {
    host: process.env.REDIS_HOST || 'localhost',
    port: parseInt(process.env.REDIS_PORT || '6379', 10),
    password: process.env.REDIS_PASSWORD || undefined,
    db: parseInt(process.env.REDIS_DB || '0', 10),
  },

  // MySQL (via Prisma)
  databaseUrl: process.env.DATABASE_URL || 'mysql://root:password@localhost:3306/gala',

  // JWT (for session tokens)
  jwtSecret: process.env.JWT_SECRET || 'dev-secret-change-in-production',
  jwtExpiresIn: process.env.JWT_EXPIRES_IN || '24h',

  // Socket.io
  socket: {
    pingTimeout: 10000,
    pingInterval: 5000,
    maxHttpBufferSize: 1e6, // 1MB
  },

  // Voting
  voting: {
    maxVotesPerUser: 7,
    lockTtlMs: 5000,
  },

  // Sync
  sync: {
    batchSize: 100,
    intervalMs: 1000,
  },
} as const;

export type Config = typeof config;
