"""
Tests for the CardFactory class.

Tests cover:
- Card type registration validation
- Unknown card type handling
"""

import pytest


class TestCardFactory:
    """Tests for the CardFactory class."""

    def test_register_card_type_invalid(self):
        """Error on non-BaseCard subclass registration."""
        from local_deep_research.news.core.card_factory import CardFactory

        # Try to register a non-BaseCard class
        class NotACard:
            pass

        with pytest.raises(ValueError) as exc_info:
            CardFactory.register_card_type("invalid", NotACard)

        assert "must be a subclass of BaseCard" in str(exc_info.value)

    def test_create_card_unknown_type(self):
        """ValueError on unknown card type."""
        from local_deep_research.news.core.card_factory import CardFactory
        from local_deep_research.news.core.base_card import CardSource

        source = CardSource(
            type="test",
            source_id="test-123",
            created_from="test",
        )

        with pytest.raises(ValueError) as exc_info:
            CardFactory.create_card(
                card_type="nonexistent_type",
                topic="Test Topic",
                source=source,
                user_id="user-123",
            )

        assert "Unknown card type" in str(exc_info.value)
        assert "nonexistent_type" in str(exc_info.value)
        assert "Available types" in str(exc_info.value)

    def test_registered_card_types(self):
        """Verify default card types are registered."""
        from local_deep_research.news.core.card_factory import CardFactory

        # Default types should be registered
        assert "news" in CardFactory._card_types
        assert "research" in CardFactory._card_types
        assert "update" in CardFactory._card_types
        assert "overview" in CardFactory._card_types
