// Debug _callProvider method
import { default as IAEngine } from './src/DRS/services/IAEngine.js';

class DebugIAEngine extends IAEngine {
    async _callProvider(provider, prompt, options) {
        console.log(`🔍 _callProvider called with provider: ${provider}`);
        console.log(`🔍 apiKeys exists: ${!!this.apiKeys}`);
        console.log(`🔍 apiKeys.mock: ${this.apiKeys?.mock}`);

        if (this.apiKeys) {
            console.log(`🔍 Available keys: ${Object.keys(this.apiKeys)}`);
            const keyName = `${provider.toUpperCase()}_API_KEY`;
            console.log(`🔍 Looking for key: ${keyName}`);
            console.log(`🔍 Key exists: ${!!this.apiKeys[keyName]}`);
            if (this.apiKeys[keyName]) {
                console.log(`🔍 Key preview: ${this.apiKeys[keyName].substring(0, 15)}...`);
            }
        }

        return super._callProvider(provider, prompt, options);
    }
}

async function debugCallProvider() {
    console.log('🔧 Debugging _callProvider method...');

    const engine = new DebugIAEngine();
    await new Promise(resolve => setTimeout(resolve, 1000));

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

debugCallProvider().catch(console.error);