// Test rapide de variance avec une seule instance
import { default as IAEngine } from './src/DRS/services/IAEngine.js';

async function testVarianceQuick() {
    console.log('⚡ TEST RAPIDE DE VARIANCE - Contenus très différents\n');

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

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

    // Tests avec contenus complètement différents pour éviter cache
    const quickTests = [
        {
            name: 'WRONG: Science -> Nonsense',
            test: () => engine.validateComprehension(
                'Albert Einstein developed the theory of relativity in the early 20th century.',
                'Dancing unicorns eat rainbow cookies in space',
                { exerciseType: 'physics-comprehension' }
            ),
            expected: 'LOW'
        },
        {
            name: 'CORRECT: History understanding',
            test: () => engine.validateComprehension(
                'World War II ended in 1945 when Japan surrendered after atomic bombs.',
                'World War 2 finished in 1945 when Japan gave up after nuclear attacks',
                { exerciseType: 'history-analysis' }
            ),
            expected: 'HIGH'
        },
        {
            name: 'WRONG: French translation nonsense',
            test: () => engine.validateTranslation(
                'Where is the library?',
                'Elephant potato singing moon',
                { fromLang: 'en', toLang: 'fr', context: 'directions' }
            ),
            expected: 'LOW'
        },
        {
            name: 'CORRECT: Spanish translation',
            test: () => engine.validateTranslation(
                'What time is it?',
                '¿Qué hora es?',
                { fromLang: 'en', toLang: 'es', context: 'time' }
            ),
            expected: 'HIGH'
        }
    ];

    const results = [];

    for (const test of quickTests) {
        try {
            console.log(`🧪 ${test.name}`);
            const result = await test.test();

            const appropriate = (test.expected === 'LOW' && result.score <= 30) ||
                              (test.expected === 'HIGH' && result.score >= 70);

            console.log(`   Score: ${result.score} (expected ${test.expected})`);
            console.log(`   ✅ Appropriate: ${appropriate ? 'YES' : 'NO'}`);
            console.log(`   Provider: ${result.provider}\n`);

            results.push({
                name: test.name,
                score: result.score,
                expected: test.expected,
                appropriate: appropriate
            });

        } catch (error) {
            console.log(`   ❌ Error: ${error.message}\n`);
        }

        await new Promise(resolve => setTimeout(resolve, 4000));
    }

    // Quick summary
    const passed = results.filter(r => r.appropriate).length;
    const total = results.length;

    console.log('🎯 QUICK VARIANCE TEST RESULTS:');
    console.log(`Passed: ${passed}/${total} (${Math.round((passed/total)*100)}%)`);

    results.forEach(r => {
        console.log(`${r.appropriate ? '✅' : '❌'} ${r.name}: ${r.score} (${r.expected})`);
    });

    if (passed === total) {
        console.log('\n🎉 SCORING SYSTEM WORKING PERFECTLY!');
    } else {
        console.log('\n⚠️ Some inconsistencies detected');
    }

    return results;
}

testVarianceQuick().catch(console.error);