import 'dotenv/config';

function int(name: string, def: number): number {
  const v = process.env[name];
  return v ? parseInt(v, 10) : def;
}
function str(name: string, def: string): string {
  return process.env[name] ?? def;
}

export const config = {
  pg: {
    host:     str('PGHOST', 'localhost'),
    port:     int('PGPORT', 5432),
    user:     str('PGUSER', 'mocl'),
    password: str('PGPASSWORD', 'change-me'),
    database: str('PGDATABASE', 'mocl'),
    readerMax: int('PG_READER_POOL_MAX', 20),
    writerMax: int('PG_WRITER_POOL_MAX', 10),
  },
  redis: {
    host: str('REDIS_HOST', 'localhost'),
    port: int('REDIS_PORT', 6379),
  },
  http: {
    port: int('HTTP_PORT', 3000),
    wsPath: str('WS_PATH', '/ws'),
  },
  devAuth: {
    userId: str('DEV_USER_ID', '1'),
    userName: str('DEV_USER_NAME', 'dev'),
  },
} as const;

export type Config = typeof config;
