"""
Comprehensive tests for subscription_manager/storage.py module.
Tests SQLSubscriptionStorage class interface and basic behavior.
"""

import pytest
from unittest.mock import MagicMock


class TestSQLSubscriptionStorageInit:
    """Tests for SQLSubscriptionStorage initialization."""

    def test_requires_session(self):
        """Test requires a session parameter."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

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

    def test_stores_session(self):
        """Test stores the session in _session attribute."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

        assert storage.session is mock_session


class TestSQLSubscriptionStorageMethods:
    """Tests for SQLSubscriptionStorage method signatures."""

    def test_has_create_method(self):
        """Test has create method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_get_active_subscriptions_method(self):
        """Test has get_active_subscriptions method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_get_due_subscriptions_method(self):
        """Test has get_due_subscriptions method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_update_refresh_time_method(self):
        """Test has update_refresh_time method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_increment_stats_method(self):
        """Test has increment_stats method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_pause_subscription_method(self):
        """Test has pause_subscription method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_resume_subscription_method(self):
        """Test has resume_subscription method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

    def test_has_expire_subscription_method(self):
        """Test has expire_subscription method."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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


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

    def test_create_accepts_data_dict(self):
        """Test create accepts data dictionary."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(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.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

        assert "id" in params

    def test_get_active_subscriptions_accepts_user_id(self):
        """Test get_active_subscriptions accepts optional user_id."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

        assert "user_id" in params

    def test_get_due_subscriptions_accepts_limit(self):
        """Test get_due_subscriptions accepts limit parameter."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

        assert "limit" in params

    def test_update_refresh_time_accepts_subscription_id(self):
        """Test update_refresh_time accepts subscription_id parameter."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

        assert "subscription_id" in params

    def test_pause_subscription_accepts_subscription_id(self):
        """Test pause_subscription accepts subscription_id parameter."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLSubscriptionStorage(mock_session)

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

        assert "subscription_id" in params


class TestSQLSubscriptionStorageInheritance:
    """Tests for class inheritance."""

    def test_extends_subscription_storage(self):
        """Test SQLSubscriptionStorage extends SubscriptionStorage."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )
        from local_deep_research.news.core.storage import SubscriptionStorage

        assert issubclass(SQLSubscriptionStorage, SubscriptionStorage)


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

    def test_imports_sql_subscription_storage(self):
        """Test SQLSubscriptionStorage can be imported."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        assert SQLSubscriptionStorage is not None

    def test_is_class(self):
        """Test SQLSubscriptionStorage is a class."""
        from local_deep_research.news.subscription_manager.storage import (
            SQLSubscriptionStorage,
        )

        assert isinstance(SQLSubscriptionStorage, type)
