export interface Config {
  port: number;
  nodeEnv: string;
  redisUrl: string;
  pansouUrl: string;
  pansouAuthToken: string;
  videoParserUrl: string;
  jwtSecret: string;
  adminUsername: string;
  adminPassword: string;
  validation: {
    concurrency: number;
    timeout: number;
    cacheTtlValid: number;
    cacheTtlInvalid: number;
  };
  corsOrigin: string;
  cookieEncryptionKey: string;
  logLevel: string;
  appVersionFile: string;
  uploadDir: string;
  chromiumPath: string;
  dbPath: string;
}

const config: Config = {
  port: parseInt(process.env.PORT || '9527', 10),
  nodeEnv: process.env.NODE_ENV || 'development',
  redisUrl: process.env.REDIS_URL || 'redis://localhost:6379',
  pansouUrl: process.env.PANSOU_URL || 'http://localhost:8888',
  pansouAuthToken: process.env.PANSOU_AUTH_TOKEN || '',
  videoParserUrl: process.env.VIDEO_PARSER_URL || 'http://localhost:3001',
  jwtSecret: process.env.JWT_SECRET || 'cloudsearch-jwt-secret-dev',
  adminUsername: process.env.ADMIN_USERNAME || 'admin',
  adminPassword: process.env.ADMIN_PASSWORD || 'admin123',
  validation: {
    concurrency: parseInt(process.env.VALIDATION_CONCURRENCY || '10', 10),
    timeout: parseInt(process.env.VALIDATION_TIMEOUT || '5000', 10),
    cacheTtlValid: parseInt(process.env.CACHE_TTL_VALID || '14400', 10),    // 4小时
    cacheTtlInvalid: parseInt(process.env.CACHE_TTL_INVALID || '3600', 10),  // 1小时
  },
  corsOrigin: process.env.CORS_ORIGIN || '',
  cookieEncryptionKey: process.env.COOKIE_ENCRYPTION_KEY || '',
  logLevel: process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug'),
  appVersionFile: process.env.APP_VERSION_FILE || '/app/VERSION',
  uploadDir: process.env.UPLOAD_DIR || '/app/uploads',
  chromiumPath: process.env.CHROMIUM_PATH || "/usr/bin/chromium-browser",
  dbPath: process.env.DB_PATH || './data/cloudsearch.db',
};

// Startup validation done by startup-validator
export default config;
