"""Tests for risk manager."""

import pytest
from src.risk.manager import get_risk_manager, RiskManager


class TestRiskManager:
    """Tests for RiskManager."""
    
    @pytest.fixture
    def risk_manager(self):
        """Create risk manager instance."""
        return get_risk_manager()
    
    @pytest.mark.asyncio
    async def test_check_trade_risk(self, risk_manager):
        """Test trade risk checking."""
        # Test with valid trade
        result = await risk_manager.check_trade_risk(
            exchange_id=1,
            strategy_id=1,
            symbol="BTC/USD",
            side="buy",
            amount=0.01,
            price=50000.0,
            current_portfolio_value=10000.0
        )
        
        assert isinstance(result, bool)
    
    @pytest.mark.asyncio
    async def test_check_max_drawdown(self, risk_manager):
        """Test max drawdown check."""
        result = await risk_manager.check_max_drawdown(
            current_portfolio_value=9000.0,
            peak_portfolio_value=10000.0
        )
        
        assert isinstance(result, bool)
    
    @pytest.mark.asyncio
    async def test_add_risk_limit(self, risk_manager, mock_database):
        """Test adding risk limit."""
        engine, Session = mock_database
        
        await risk_manager.add_risk_limit(
            limit_type="max_drawdown",
            value=0.10,  # 10%
            is_active=True
        )
        
        # Verify limit was added
        await risk_manager.load_risk_limits()
        assert len(risk_manager.risk_limits) > 0

