// Debug script to test the automation-v2 page API calls
const debug = async () => {
  const baseUrl = 'http://localhost:9001';
  
  console.log('🔍 Testing all APIs used by automation-v2 page...\n');
  
  try {
    // Test automation status
    console.log('1. Testing /api/automation/status...');
    const statusResponse = await fetch(`${baseUrl}/api/automation/status`);
    const statusData = await statusResponse.json();
    console.log('Status:', statusData);
    console.log('');
    
    // Test analysis details
    console.log('2. Testing /api/automation/analysis-details...');
    const analysisResponse = await fetch(`${baseUrl}/api/automation/analysis-details`);
    const analysisData = await analysisResponse.json();
    console.log('Analysis:', {
      success: analysisData.success,
      hasAnalysis: !!analysisData.data?.analysis,
      decision: analysisData.data?.analysis?.decision,
      confidence: analysisData.data?.analysis?.confidence,
      timestamp: analysisData.data?.analysis?.timestamp
    });
    console.log('');
    
    // Test learning status
    console.log('3. Testing /api/automation/learning-status...');
    const learningResponse = await fetch(`${baseUrl}/api/automation/learning-status`);
    const learningData = await learningResponse.json();
    console.log('Learning Status:', learningData);
    console.log('');
    
    // Test AI learning status
    console.log('4. Testing /api/ai-learning-status...');
    const aiLearningResponse = await fetch(`${baseUrl}/api/ai-learning-status`);
    const aiLearningData = await aiLearningResponse.json();
    console.log('AI Learning Data:', {
      success: aiLearningData.success,
      totalTrades: aiLearningData.data?.statistics?.totalTrades,
      winRate: aiLearningData.data?.statistics?.winRate,
      totalPnl: aiLearningData.data?.statistics?.totalPnl
    });
    console.log('');
    
    // Simulate the component's logic
    console.log('5. Simulating component logic...');
    const hasTradeData = (aiLearningData.data?.statistics?.totalTrades || 0) > 0;
    const isSystemActive = learningData.learningSystem?.enabled || hasTradeData;
    
    console.log('hasTradeData:', hasTradeData);
    console.log('learningSystem.enabled:', learningData.learningSystem?.enabled);
    console.log('isSystemActive:', isSystemActive);
    console.log('');
    
    // Check if analysis is real or mock
    console.log('6. Analysis data check...');
    const hasRealAnalysis = analysisData.success && analysisData.data?.analysis?.timestamp;
    console.log('hasRealAnalysis:', hasRealAnalysis);
    console.log('Latest analysis decision:', analysisData.data?.analysis?.decision);
    console.log('Latest analysis timestamp:', analysisData.data?.analysis?.timestamp);
    
  } catch (error) {
    console.error('Error during debug:', error);
  }
};

debug();
