"""
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": "auto",
            "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 auto."""
        default_settings = {
            "search_engine": "auto",
        }

        assert default_settings["search_engine"] == "auto"

    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


class TestWebModuleImports:
    """Tests for web module imports."""

    def test_web_module_importable(self):
        """Web module is importable."""
        from local_deep_research.news import web

        assert web is not None

    def test_api_import_in_web(self):
        """api module is imported in web module."""
        from local_deep_research.news.web import api

        assert api is not None


class TestFlaskApiBlueprint:
    """Tests for flask_api blueprint integration."""

    def test_flask_api_module_exists(self):
        """flask_api module exists."""
        from local_deep_research.news import flask_api

        assert flask_api is not None

    def test_news_api_bp_exists(self):
        """news_api_bp exists in flask_api."""
        from local_deep_research.news.flask_api import news_api_bp

        assert news_api_bp is not None
