import dotenv from 'dotenv';
import path from 'path';

// 使用 process.cwd() 获取项目根目录（server目录）
const projectRoot = process.cwd();
dotenv.config({ path: path.resolve(projectRoot, '.env') });

export const config = {
  port: parseInt(process.env.PORT || '3000', 10),
  nodeEnv: process.env.NODE_ENV || 'development',
  
  mongodb: {
    uri: process.env.MONGODB_URI || 'mongodb://localhost:27017/audio-book',
  },
  
  jwt: {
    // 临时硬编码，确保登录和验证一致
    secret: 'my-jwt-secret-key-2024',
    expiresIn: process.env.JWT_EXPIRES_IN || '7d',
  },
  
  // 阿里云百炼 DashScope TTS
  dashscope: {
    apiKey: process.env.DASHSCOPE_API_KEY || '',
    model: process.env.DASHSCOPE_MODEL || 'qwen3-tts-instruct-flash',
    voice: process.env.DASHSCOPE_VOICE || 'Cherry',
    // 可用 TTS 模型列表（随机选用）
    ttsModels: (process.env.DASHSCOPE_TTS_MODELS || 'qwen3-tts-instruct-flash').split(',').filter(Boolean),
    // 长文本模式使用 WebSocket 实时合成
    useRealtime: process.env.DASHSCOPE_USE_REALTIME === 'true',
    realtimeModel: process.env.DASHSCOPE_REALTIME_MODEL || 'qwen3-tts-instruct-flash-realtime',
  },
  
  upload: {
    dir: path.join(process.cwd(), 'uploads'),
    maxSize: 50 * 1024 * 1024, // 50MB
  },
};