"""Tests for backend dependencies."""

import pytest
from unittest.mock import patch, Mock
from backend.core.dependencies import (
    get_database, get_trading_engine, get_portfolio_tracker,
    get_strategy_registry, get_backtesting_engine, get_exchange_factory
)


class TestGetDatabase:
    """Tests for get_database dependency."""
    
    def test_get_database_singleton(self):
        """Test that get_database returns same instance."""
        db1 = get_database()
        db2 = get_database()
        # Should be cached/same instance due to lru_cache
        assert db1 is db2


class TestGetTradingEngine:
    """Tests for get_trading_engine dependency."""
    
    @patch('backend.core.dependencies.get_trading_engine')
    def test_get_trading_engine(self, mock_get_engine):
        """Test getting trading engine."""
        mock_engine = Mock()
        mock_get_engine.return_value = mock_engine
        engine = get_trading_engine()
        assert engine is not None


class TestGetPortfolioTracker:
    """Tests for get_portfolio_tracker dependency."""
    
    @patch('backend.core.dependencies.get_portfolio_tracker')
    def test_get_portfolio_tracker(self, mock_get_tracker):
        """Test getting portfolio tracker."""
        mock_tracker = Mock()
        mock_get_tracker.return_value = mock_tracker
        tracker = get_portfolio_tracker()
        assert tracker is not None


class TestGetStrategyRegistry:
    """Tests for get_strategy_registry dependency."""
    
    @patch('backend.core.dependencies.get_strategy_registry')
    def test_get_strategy_registry(self, mock_get_registry):
        """Test getting strategy registry."""
        mock_registry = Mock()
        mock_get_registry.return_value = mock_registry
        registry = get_strategy_registry()
        assert registry is not None


class TestGetBacktestingEngine:
    """Tests for get_backtesting_engine dependency."""
    
    @patch('backend.core.dependencies.get_backtesting_engine')
    def test_get_backtesting_engine(self, mock_get_engine):
        """Test getting backtesting engine."""
        mock_engine = Mock()
        mock_get_engine.return_value = mock_engine
        engine = get_backtesting_engine()
        assert engine is not None


class TestGetExchangeFactory:
    """Tests for get_exchange_factory dependency."""
    
    def test_get_exchange_factory(self):
        """Test getting exchange factory."""
        factory = get_exchange_factory()
        assert factory is not None

