"""Mock exchange adapter for testing."""

from unittest.mock import Mock, AsyncMock
from src.exchanges.base import BaseExchange


class MockExchange(BaseExchange):
    """Mock exchange adapter for testing."""
    
    def __init__(self, name: str = "mock_exchange", **kwargs):
        super().__init__(name, "mock_key", "mock_secret")
        self.is_connected = True
        self._mock_responses = {}
    
    async def connect(self):
        """Mock connection."""
        self.is_connected = True
    
    async def disconnect(self):
        """Mock disconnection."""
        self.is_connected = False
    
    async def fetch_balance(self):
        """Mock balance fetch."""
        return self._mock_responses.get('balance', {
            'USD': {'free': 1000.0, 'used': 0.0, 'total': 1000.0}
        })
    
    async def place_order(self, symbol, side, order_type, amount, price=None, params=None):
        """Mock order placement."""
        return self._mock_responses.get('order', {
            'id': 'mock_order_123',
            'status': 'filled',
            'filled': amount,
            'price': price or 50000.0
        })
    
    async def cancel_order(self, order_id, symbol=None):
        """Mock order cancellation."""
        return {'id': order_id, 'status': 'canceled'}
    
    async def fetch_order_status(self, order_id, symbol=None):
        """Mock order status fetch."""
        return self._mock_responses.get('order_status', {
            'id': order_id,
            'status': 'filled'
        })
    
    async def fetch_ohlcv(self, symbol, timeframe, since=None, limit=None):
        """Mock OHLCV fetch."""
        return self._mock_responses.get('ohlcv', [])
    
    async def subscribe_ohlcv(self, symbol, timeframe, callback):
        """Mock OHLCV subscription."""
        pass
    
    async def subscribe_trades(self, symbol, callback):
        """Mock trades subscription."""
        pass
    
    async def subscribe_order_book(self, symbol, callback):
        """Mock order book subscription."""
        pass
    
    async def fetch_open_orders(self, symbol=None):
        """Mock open orders fetch."""
        return self._mock_responses.get('open_orders', [])
    
    async def fetch_positions(self, symbol=None):
        """Mock positions fetch."""
        return self._mock_responses.get('positions', [])
    
    async def fetch_markets(self):
        """Mock markets fetch."""
        return self._mock_responses.get('markets', [])

