#!/usr/bin/env node

/**
 * Test Stop Loss / Take Profit Implementation in Automation
 */

const { simpleAutomation } = require('./lib/simple-automation.js');

async function testSLTPImplementation() {
  console.log('🧪 Testing SL/TP Implementation in Simple Automation...');
  
  // Mock analysis data with current price
  const mockAnalysis = {
    recommendation: 'BUY',
    confidence: 85,
    currentPrice: 186.50,
    reasoning: 'Strong bullish signal'
  };
  
  // Mock config
  const mockConfig = {
    symbol: 'SOLUSD',
    tradingAmount: 100,
    leverage: 1,
    mode: 'SIMULATION' // Keep in simulation for testing
  };
  
  // Set up automation with mock config
  simpleAutomation.config = mockConfig;
  
  console.log('📊 Mock Analysis:', mockAnalysis);
  console.log('⚙️ Mock Config:', mockConfig);
  
  try {
    // Test the executeTrade method
    console.log('\n🎯 Testing executeTrade with SL/TP calculation...');
    
    // This will show us what payload would be sent
    const result = await simpleAutomation.executeTrade(mockAnalysis);
    
    console.log('✅ Trade execution test completed');
    console.log('📊 Result:', result);
    
  } catch (error) {
    console.error('❌ Test failed:', error);
  }
  
  console.log('\n🔍 Expected behavior:');
  console.log('   💰 Entry: ~$186.50');
  console.log('   🛑 Stop Loss: ~$177.18 (5% below)');
  console.log('   🎯 Take Profit: ~$205.15 (10% above)');
  console.log('   📊 Risk/Reward: 2:1 ratio');
}

testSLTPImplementation();
