"""
Comprehensive tests for SQLCardStorage class.
Tests interface, method signatures, and inheritance.
"""

import pytest
from unittest.mock import MagicMock


class TestSQLCardStorageInit:
    """Tests for SQLCardStorage initialization."""

    def test_requires_session(self):
        """Test requires a session parameter."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        with pytest.raises(ValueError):
            SQLCardStorage(None)

    def test_stores_session(self):
        """Test stores the session in _session attribute."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert storage._session is mock_session

    def test_session_property_returns_session(self):
        """Test session property returns the stored session."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert storage.session is mock_session


class TestSQLCardStorageMethods:
    """Tests for SQLCardStorage method signatures."""

    def test_has_create_method(self):
        """Test has create method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "create")
        assert callable(storage.create)

    def test_has_get_method(self):
        """Test has get method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "get")
        assert callable(storage.get)

    def test_has_update_method(self):
        """Test has update method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "update")
        assert callable(storage.update)

    def test_has_delete_method(self):
        """Test has delete method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "delete")
        assert callable(storage.delete)

    def test_has_list_method(self):
        """Test has list method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "list")
        assert callable(storage.list)

    def test_has_get_by_user_method(self):
        """Test has get_by_user method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "get_by_user")
        assert callable(storage.get_by_user)

    def test_has_get_latest_version_method(self):
        """Test has get_latest_version method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "get_latest_version")
        assert callable(storage.get_latest_version)

    def test_has_add_version_method(self):
        """Test has add_version method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "add_version")
        assert callable(storage.add_version)

    def test_has_update_latest_info_method(self):
        """Test has update_latest_info method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "update_latest_info")
        assert callable(storage.update_latest_info)

    def test_has_archive_card_method(self):
        """Test has archive_card method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "archive_card")
        assert callable(storage.archive_card)

    def test_has_pin_card_method(self):
        """Test has pin_card method."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        assert hasattr(storage, "pin_card")
        assert callable(storage.pin_card)


class TestSQLCardStorageMethodSignatures:
    """Tests for method parameter signatures."""

    def test_create_accepts_data_dict(self):
        """Test create accepts data dictionary."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.create)
        params = list(sig.parameters.keys())

        assert "data" in params

    def test_get_accepts_id(self):
        """Test get accepts id parameter."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.get)
        params = list(sig.parameters.keys())

        assert "id" in params

    def test_update_accepts_id_and_data(self):
        """Test update accepts id and data parameters."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.update)
        params = list(sig.parameters.keys())

        assert "id" in params
        assert "data" in params

    def test_delete_accepts_id(self):
        """Test delete accepts id parameter."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.delete)
        params = list(sig.parameters.keys())

        assert "id" in params

    def test_list_accepts_filters_limit_offset(self):
        """Test list accepts filters, limit, and offset parameters."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.list)
        params = list(sig.parameters.keys())

        assert "filters" in params
        assert "limit" in params
        assert "offset" in params

    def test_get_by_user_accepts_user_id(self):
        """Test get_by_user accepts user_id parameter."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.get_by_user)
        params = list(sig.parameters.keys())

        assert "user_id" in params

    def test_archive_card_accepts_card_id(self):
        """Test archive_card accepts card_id parameter."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.archive_card)
        params = list(sig.parameters.keys())

        assert "card_id" in params

    def test_pin_card_accepts_card_id_and_pinned(self):
        """Test pin_card accepts card_id and pinned parameters."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        import inspect

        mock_session = MagicMock()
        storage = SQLCardStorage(mock_session)

        sig = inspect.signature(storage.pin_card)
        params = list(sig.parameters.keys())

        assert "card_id" in params
        assert "pinned" in params


class TestSQLCardStorageInheritance:
    """Tests for class inheritance."""

    def test_extends_card_storage(self):
        """Test SQLCardStorage extends CardStorage."""
        from local_deep_research.news.core.card_storage import SQLCardStorage
        from local_deep_research.news.core.storage import CardStorage

        assert issubclass(SQLCardStorage, CardStorage)


class TestSQLCardStorageImports:
    """Tests for module imports."""

    def test_is_class(self):
        """Test SQLCardStorage is a class."""
        from local_deep_research.news.core.card_storage import SQLCardStorage

        assert isinstance(SQLCardStorage, type)
