// Test live decisions API by bypassing the UI
// This will work even if the automation-v2 page has compilation errors

async function testLiveDecisionsDirectly() {
  try {
    console.log('🚀 Testing live decisions API directly...');
    
    // Test POST to add a decision
    const testDecision = {
      action: 'BUY',
      symbol: 'SOLUSD',
      confidence: 85,
      blocked: true,
      blockReason: 'Risk management blocked trade: Stop loss direction wrong (should be BELOW entry for BUY orders)',
      timestamp: new Date().toISOString(),
      details: {
        entryPrice: 245.50,
        stopLoss: 243.00,
        takeProfit: 250.00,
        leverage: 5,
        amount: 100,
        side: 'BUY',
        aiReasoning: 'Strong bullish momentum detected across multiple timeframes'
      }
    };

    console.log('📝 Posting test decision...');
    const postResponse = await fetch('http://localhost:9001/api/automation/live-decisions', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(testDecision)
    });

    console.log('📊 POST Response status:', postResponse.status);
    
    if (postResponse.status === 200) {
      console.log('✅ POST successful');
      
      // Test GET to retrieve decisions
      console.log('📋 Getting live decisions...');
      const getResponse = await fetch('http://localhost:9001/api/automation/live-decisions');
      console.log('📊 GET Response status:', getResponse.status);
      
      if (getResponse.status === 200) {
        const data = await getResponse.json();
        console.log('✅ GET successful');
        console.log('📋 Live decisions count:', data.decisions?.length || 0);
        console.log('📋 Latest decision:', data.decisions?.[0] || 'No decisions');
      } else {
        console.log('❌ GET failed');
      }
    } else {
      console.log('❌ POST failed');
    }
    
  } catch (error) {
    console.error('❌ Error testing API:', error.message);
  }
}

testLiveDecisionsDirectly();
