const { PrismaClient } = require('@prisma/client');

async function checkTradeStatuses() {
  const prisma = new PrismaClient();
  
  try {
    console.log('🔍 Checking status of trades mentioned in logs...\n');
    
    // Check specific trade IDs from the logs
    const tradeIds = [
      'cmdhqpakw0007mk1j1ptce70k',
      'cmdhq2pqf003zn51jx266y5h2',
      'cmdhpygku003nn51ju1pn43hl',
      'cmdhpt88e003dn51jzyfdcjti',
      'cmdhpr3gz0037n51jpxetojtg'
    ];
    
    for (const tradeId of tradeIds) {
      const trade = await prisma.trades.findUnique({
        where: { id: tradeId },
        select: {
          id: true,
          status: true,
          symbol: true,
          side: true,
          createdAt: true,
          isAutomated: true
        }
      });
      
      if (trade) {
        console.log(`📊 Trade ${tradeId.substring(0, 8)}...:`);
        console.log(`   Status: ${trade.status}`);
        console.log(`   Symbol: ${trade.symbol}`);
        console.log(`   Side: ${trade.side}`);
        console.log(`   Created: ${trade.createdAt}`);
        console.log(`   Automated: ${trade.isAutomated}`);
        console.log('');
      } else {
        console.log(`❌ Trade ${tradeId} not found`);
      }
    }
    
    // Count current OPEN trades
    const openTrades = await prisma.trades.count({
      where: {
        status: 'OPEN',
        isAutomated: true
      }
    });
    
    console.log(`🔴 Current OPEN automated trades: ${openTrades}`);
    
  } catch (error) {
    console.error('❌ Error checking trades:', error);
  } finally {
    await prisma.$disconnect();
  }
}

checkTradeStatuses().catch(console.error);
