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;
  };
  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小时
  },
  dbPath: process.env.DB_PATH || './data/cloudsearch.db',
};

// 生产环境强制校验关键安全配置
if (process.env.NODE_ENV === 'production') {
  if (!process.env.JWT_SECRET || process.env.JWT_SECRET === 'cloudsearch-jwt-secret-dev') {
    console.error('[FATAL] JWT_SECRET 未设置或使用了默认值，请在 .env 中设置强密码')
    process.exit(1)
  }
  if (!process.env.ADMIN_PASSWORD || process.env.ADMIN_PASSWORD === 'admin123') {
    console.error('[FATAL] ADMIN_PASSWORD 未设置或使用了默认值，请在 .env 中设置强密码')
    process.exit(1)
  }
}

export default config;
