import { RiskEngine } from '../src/services/riskEngine.js';
import { MarketContext, SignalDirection } from '../src/strategies/rules/types.js';

async function testRiskFormula() {
    console.log('--- Testing New Risk Formula ---');
    const engine = new RiskEngine();

    const mockContext: MarketContext = {
        currentPrice: 100000,
        candles4h: [],
        candles1h: Array(20).fill({ close: 100000, high: 100500, low: 99500 }),
        candles15m: [],
        change24h: 0,
        changeToday: 0,
        session: 'NY',
        isMajorSession: true,
        volatility: 'Low',
        latestSignal: SignalDirection.NONE
    };

    // Note: Since we don't have true ATR here, let's mock calculateRiskProfile call or check buildProfile
    console.log('Mock Entry: 100,000');
    console.log('Mock ATR: 1,000');
    console.log('SL Multiplier: 1.0 -> SL Dist: 1,000');
    console.log('RRR: 1.5 -> Raw TP Dist: 1,500');
    console.log('Max TP Cap (1%): 1,000');

    const profile = (engine as any).buildProfile('BTC/USD', SignalDirection.BUY, 100000, 1000, 10, 1.5);

    console.log('\nResults:');
    console.log(`SL: ${profile.stopLoss} (Expected 99,000)`);
    console.log(`TP: ${profile.takeProfit} (Expected 101,000 - capped by 1%)`);
    console.log(`Size: ${profile.positionSize}`);

    if (profile.stopLoss === 99000 && profile.takeProfit === 101000) {
        console.log('\n✅ Formula mapping is CORRECT.');
    } else {
        console.log('\n❌ Formula mapping is INCORRECT.');
    }
}

testRiskFormula().catch(console.error);
