from unittest.mock import MagicMock, patch

import pytest

from tarot.deck import Card
from tarot.ui import CardDisplay


def test_card_display_delegation():
    """Test that CardDisplay delegates to SpreadDisplay correctly."""
    with patch("tarot.ui.SpreadDisplay") as MockSpreadDisplay:
        # Mock HAS_PILLOW to True to ensure we proceed
        with patch("tarot.ui.HAS_PILLOW", True):
            display = CardDisplay()

            # Create dummy card
            card = MagicMock(spec=Card)
            card.name = "The Fool"
            card.image_path = "fool.jpg"
            cards = [card]

            display.show_cards(cards, title="Test Spread")

            # Verify SpreadDisplay was instantiated
            assert MockSpreadDisplay.call_count == 1

            # Verify run was called
            MockSpreadDisplay.return_value.run.assert_called_once()

            # Verify arguments passed to SpreadDisplay
            args, _ = MockSpreadDisplay.call_args
            reading = args[0]
            deck_name = args[1]

            assert deck_name == "default"
            assert reading.spread.name == "Card List"
            assert reading.spread.description == "Test Spread"
            assert len(reading.drawn_cards) == 1
            assert reading.drawn_cards[0].card == card
            assert reading.drawn_cards[0].position.number == 1
