// Test spécifique du bug de traduction espagnole
import { default as IAEngine } from './src/DRS/services/IAEngine.js';

async function testSpanishBug() {
    console.log('🐛 TEST SPÉCIFIQUE - Bug traduction espagnole\n');

    const engine = new IAEngine({
        defaultProvider: 'openai',
        fallbackProviders: ['deepseek']
    });

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

    console.log('Testing "What time is it?" -> "¿Qué hora es?" 5 times...\n');

    const results = [];

    for (let i = 1; i <= 5; i++) {
        try {
            console.log(`Round ${i}/5:`);
            const result = await engine.validateTranslation(
                'What time is it?',
                '¿Qué hora es?',
                {
                    fromLang: 'en',
                    toLang: 'es',
                    testRound: i,
                    timestamp: Date.now()
                }
            );

            console.log(`  Score: ${result.score}`);
            console.log(`  Provider: ${result.provider}`);
            console.log(`  Feedback: ${result.feedback?.substring(0, 100)}...`);

            results.push({
                round: i,
                score: result.score,
                provider: result.provider,
                feedback: result.feedback
            });

        } catch (error) {
            console.log(`  ❌ Error: ${error.message}`);
            results.push({
                round: i,
                score: 'ERROR',
                error: error.message
            });
        }

        await new Promise(resolve => setTimeout(resolve, 4000));
        console.log('');
    }

    console.log('📊 ANALYSE DU BUG:');
    console.log('=================\n');

    const validScores = results.filter(r => typeof r.score === 'number').map(r => r.score);

    console.log('Scores obtenus:', validScores);
    console.log(`Moyenne: ${validScores.length > 0 ? Math.round(validScores.reduce((a,b) => a+b, 0) / validScores.length) : 'N/A'}`);
    console.log(`Min-Max: ${Math.min(...validScores)}-${Math.max(...validScores)}`);
    console.log(`Tous à 0: ${validScores.every(s => s === 0) ? 'OUI' : 'NON'}`);

    if (validScores.every(s => s === 0)) {
        console.log('\n🐛 BUG CONFIRMÉ:');
        console.log('✅ Reproductible à 100%');
        console.log('❌ Traduction correcte espagnole = 0 points');
        console.log('🔧 Besoin de debug le prompt de traduction');
    } else {
        console.log('\n⚠️ VARIANCE DÉTECTÉE:');
        console.log('Le scoring n\'est pas constant');
    }

    return results;
}

testSpanishBug().catch(console.error);