"""
Comprehensive tests for rating_system/storage.py module.
Tests SQLRatingStorage class interface and basic behavior.
"""

import pytest
from unittest.mock import MagicMock


class TestSQLRatingStorageInit:
    """Tests for SQLRatingStorage initialization."""

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

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

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

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

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

        assert storage.session is mock_session


class TestSQLRatingStorageMethods:
    """Tests for SQLRatingStorage method signatures."""

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

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

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

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

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

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

    def test_has_get_user_rating_method(self):
        """Test has get_user_rating method."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

    def test_has_upsert_rating_method(self):
        """Test has upsert_rating method."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

    def test_has_get_ratings_summary_method(self):
        """Test has get_ratings_summary method."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

    def test_has_get_user_ratings_method(self):
        """Test has get_user_ratings method."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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


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

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

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

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

        assert "id" in params

    def test_get_user_rating_accepts_user_id_item_id_rating_type(self):
        """Test get_user_rating accepts user_id, item_id, and rating_type."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

        assert "user_id" in params
        assert "item_id" in params
        assert "rating_type" in params

    def test_upsert_rating_accepts_required_params(self):
        """Test upsert_rating accepts required parameters."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

        assert "user_id" in params
        assert "item_id" in params
        assert "rating_type" in params
        assert "rating_value" in params

    def test_get_ratings_summary_accepts_item_id(self):
        """Test get_ratings_summary accepts item_id parameter."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

        assert "item_id" in params

    def test_get_user_ratings_accepts_user_id(self):
        """Test get_user_ratings accepts user_id parameter."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )
        import inspect

        mock_session = MagicMock()
        storage = SQLRatingStorage(mock_session)

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

        assert "user_id" in params


class TestSQLRatingStorageInheritance:
    """Tests for class inheritance."""

    def test_extends_rating_storage(self):
        """Test SQLRatingStorage extends RatingStorage."""
        from local_deep_research.news.rating_system.storage import (
            SQLRatingStorage,
        )
        from local_deep_research.news.core.storage import RatingStorage

        assert issubclass(SQLRatingStorage, RatingStorage)


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

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

        assert isinstance(SQLRatingStorage, type)
