"""Tests for order manager."""

import pytest
from unittest.mock import Mock, patch
from src.trading.order_manager import get_order_manager, OrderManager


class TestOrderManager:
    """Tests for OrderManager."""
    
    @pytest.fixture
    def order_manager(self, mock_database):
        """Create order manager instance."""
        return get_order_manager()
    
    @pytest.mark.asyncio
    async def test_create_order(self, order_manager, mock_database):
        """Test order creation."""
        engine, Session = mock_database
        
        order = await order_manager.create_order(
            exchange_id=1,
            strategy_id=1,
            symbol="BTC/USD",
            side="buy",
            order_type="market",
            amount=0.01,
            price=50000.0,
            is_paper_trade=True
        )
        
        assert order is not None
        assert order.symbol == "BTC/USD"
        assert order.side == "buy"
        assert order.status == "pending"
    
    @pytest.mark.asyncio
    async def test_update_order_status(self, order_manager, mock_database):
        """Test order status update."""
        engine, Session = mock_database
        
        # Create order first
        order = await order_manager.create_order(
            exchange_id=1,
            strategy_id=1,
            symbol="BTC/USD",
            side="buy",
            order_type="market",
            amount=0.01,
            is_paper_trade=True
        )
        
        # Update status
        updated = await order_manager.update_order_status(
            client_order_id=order.client_order_id,
            new_status="filled",
            filled_amount=0.01,
            cost=500.0
        )
        
        assert updated is not None
        assert updated.status == "filled"
    
    def test_get_order(self, order_manager, mock_database):
        """Test getting order."""
        # This would require creating an order first
        # Simplified test
        order = order_manager.get_order(client_order_id="nonexistent")
        assert order is None

