// Debug DeepSeek API key loading
import { config } from 'dotenv';
import { default as IAEngine } from './src/DRS/services/IAEngine.js';

async function debugDeepSeekKeys() {
    config();

    console.log('🔍 DeepSeek API key debugging...');
    console.log('DEEPSEEK_API_KEY exists:', !!process.env.DEEPSEEK_API_KEY);
    console.log('DEEPSEEK_API_KEY length:', process.env.DEEPSEEK_API_KEY?.length);
    console.log('DEEPSEEK_API_KEY preview:', process.env.DEEPSEEK_API_KEY?.substring(0, 20) + '...');

    // Test IAEngine loading
    const engine = new IAEngine();
    await new Promise(resolve => setTimeout(resolve, 1000));

    console.log('\n🔍 IAEngine API keys loaded:');
    console.log('Available keys:', Object.keys(engine.apiKeys || {}));
    console.log('DeepSeek key in engine:', !!engine.apiKeys?.DEEPSEEK_API_KEY);
    if (engine.apiKeys?.DEEPSEEK_API_KEY) {
        console.log('DeepSeek key value:', engine.apiKeys.DEEPSEEK_API_KEY.substring(0, 20) + '...');
    }

    // Test direct DeepSeek call
    try {
        console.log('\n🧪 Testing direct DeepSeek call...');
        const result = await engine.validateEducationalContent('Test', {
            preferredProvider: 'deepseek'
        });
        console.log('✅ DeepSeek works! Provider:', result.provider);
    } catch (error) {
        console.log('❌ DeepSeek failed:', error.message);
    }
}

debugDeepSeekKeys().catch(console.error);