const { DriftTradingService } = require('./lib/drift-trading.ts')

async function testDirectBalance() {
  console.log('🔍 Testing direct balance retrieval with detailed logging...')
  
  try {
    const driftService = new DriftTradingService()
    
    console.log('🔐 Attempting login...')
    const loginResult = await driftService.login()
    console.log('✅ Login result:', JSON.stringify(loginResult, null, 2))
    
    if (loginResult.isLoggedIn && loginResult.userAccountExists) {
      console.log('\n💰 Getting account balance...')
      const balance = await driftService.getAccountBalance()
      console.log('📊 Balance result:', JSON.stringify(balance, null, 2))
      
      console.log('\n📈 Getting positions...')
      const positions = await driftService.getPositions()
      console.log('📊 Positions result:', JSON.stringify(positions, null, 2))
    } else {
      console.log('❌ Login failed or account does not exist')
    }
    
  } catch (error) {
    console.error('❌ Error:', error.message)
    console.error('📊 Stack trace:', error.stack)
  }
}

testDirectBalance()
  .then(() => console.log('✅ Test completed'))
  .catch(error => console.error('❌ Test failed:', error))
