// Simple test to verify the "nein" response fix
const fetch = require('node-fetch');

async function testNeinResponse() {
    console.log('🎯 Testing the "nein" response fix...\n');
    
    try {
        const response = await fetch('http://localhost:3002/api/respond-to-answer', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                answer: "nein",
                question: "Weißt du, wie das Magnetfeld der Erde entsteht?",
                originalTopic: "Wie entstehen Polarlichter?",
                language: "de",
                sessionId: "test-nein-123"
            })
        });
        
        const data = await response.json();
        const aiResponse = data.response || '';
        
        console.log('🤖 AI Response to "nein":');
        console.log('"' + aiResponse + '"');
        console.log();
        
        // Check if response is appropriate
        const hasWrongPhrase = aiResponse.includes('interessante Frage');
        const hasAppropriatePhrase = aiResponse.includes('in Ordnung') || 
                                    aiResponse.includes('ehrlich') || 
                                    aiResponse.includes('verstehen') ||
                                    aiResponse.includes('Das ist völlig in Ordnung');
        
        console.log('📊 ANALYSIS:');
        console.log('❌ Contains "interessante Frage" (bad):', hasWrongPhrase);
        console.log('✅ Contains appropriate response (good):', hasAppropriatePhrase);
        console.log();
        
        if (!hasWrongPhrase && hasAppropriatePhrase) {
            console.log('🎉 SUCCESS! The fix is working perfectly!');
            console.log('✅ The AI no longer says "Das ist eine interessante Frage!" when child says "nein"');
            console.log('✅ Instead, it responds appropriately to acknowledge the "no" answer');
        } else if (hasWrongPhrase) {
            console.log('❌ BUG STILL EXISTS: AI still says "interessante Frage" for "nein" responses');
        } else {
            console.log('🤔 Response seems neutral - may need further testing');
        }
        
    } catch (error) {
        console.error('❌ Test failed:', error.message);
    }
}

testNeinResponse();
