"""
Extended tests for news/web.py

Tests cover:
- create_news_blueprint() function
- Blueprint structure and configuration
- Default settings
"""


class TestCreateNewsBlueprint:
    """Tests for create_news_blueprint() function."""

    def test_function_exists(self):
        """create_news_blueprint function exists."""
        from local_deep_research.news.web import create_news_blueprint

        assert callable(create_news_blueprint)

    def test_returns_blueprint_instance(self):
        """Returns a Flask Blueprint instance."""
        from local_deep_research.news.web import create_news_blueprint
        from flask import Blueprint

        bp = create_news_blueprint()

        assert isinstance(bp, Blueprint)

    def test_blueprint_name_is_news(self):
        """Blueprint name is 'news'."""
        from local_deep_research.news.web import create_news_blueprint

        bp = create_news_blueprint()

        assert bp.name == "news"


class TestNewsBlueprintRoutes:
    """Tests for blueprint route registration."""

    def test_has_deferred_functions(self):
        """Blueprint has registered routes."""
        from local_deep_research.news.web import create_news_blueprint

        bp = create_news_blueprint()

        # Should have deferred functions (routes)
        assert len(bp.deferred_functions) > 0


class TestDefaultSettings:
    """Tests for default settings."""

    def test_default_iterations(self):
        """Default iterations is 3."""
        default_settings = {
            "iterations": 3,
            "questions_per_iteration": 5,
            "search_engine": "searxng",
            "model_provider": "OLLAMA",
            "model": "",
            "search_strategy": "source-based",
        }

        assert default_settings["iterations"] == 3

    def test_default_questions_per_iteration(self):
        """Default questions_per_iteration is 5."""
        default_settings = {
            "iterations": 3,
            "questions_per_iteration": 5,
        }

        assert default_settings["questions_per_iteration"] == 5

    def test_default_search_engine(self):
        """Default search_engine is searxng."""
        default_settings = {
            "search_engine": "searxng",
        }

        assert default_settings["search_engine"] == "searxng"

    def test_default_model_provider(self):
        """Default model_provider is OLLAMA."""
        default_settings = {
            "model_provider": "OLLAMA",
        }

        assert default_settings["model_provider"] == "OLLAMA"

    def test_default_search_strategy(self):
        """Default search_strategy is source-based."""
        default_settings = {
            "search_strategy": "source-based",
        }

        assert default_settings["search_strategy"] == "source-based"


class TestStrategiesConfiguration:
    """Tests for search strategies configuration."""

    def test_available_strategies(self):
        """Available strategies list."""
        strategies = [
            "topic_based",
            "news_aggregation",
            "source_based",
            "focused_iteration",
        ]

        assert "topic_based" in strategies
        assert "news_aggregation" in strategies
        assert "source_based" in strategies
        assert "focused_iteration" in strategies

    def test_default_strategy(self):
        """Default strategy is topic_based."""
        default_strategy = "topic_based"

        assert default_strategy == "topic_based"


class TestBlueprintConfiguration:
    """Tests for blueprint configuration."""

    def test_blueprint_can_be_created_multiple_times(self):
        """Blueprint can be created multiple times."""
        from local_deep_research.news.web import create_news_blueprint

        bp1 = create_news_blueprint()
        bp2 = create_news_blueprint()

        # Both should be valid blueprints
        assert bp1 is not None
        assert bp2 is not None
