"""
Behavioral tests for evidence/requirements module.

Tests EvidenceRequirements class with get_requirements() and get_minimum_confidence().
"""


class TestGetRequirements:
    """Tests for EvidenceRequirements.get_requirements() method."""

    def test_property_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.PROPERTY)
        assert "preferred" in req
        assert "acceptable" in req
        assert "sources" in req
        assert "direct_statement" in req["preferred"]

    def test_name_pattern_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.NAME_PATTERN)
        assert "linguistic_analysis" in req["preferred"]

    def test_event_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.EVENT)
        assert "news_report" in req["preferred"]

    def test_statistic_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.STATISTIC)
        assert "statistical_data" in req["preferred"]

    def test_temporal_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.TEMPORAL)
        assert "official_record" in req["preferred"]

    def test_location_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.LOCATION)
        assert "geographical_data" in req["preferred"]

    def test_comparison_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.COMPARISON)
        assert "statistical_comparison" in req["preferred"]

    def test_existence_requirements(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        req = EvidenceRequirements.get_requirements(ConstraintType.EXISTENCE)
        assert "direct_statement" in req["preferred"]

    def test_all_requirements_have_three_keys(self):
        """All constraint types should have preferred, acceptable, and sources."""
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        for ct in ConstraintType:
            req = EvidenceRequirements.get_requirements(ct)
            assert "preferred" in req
            assert "acceptable" in req
            assert "sources" in req

    def test_all_requirements_have_non_empty_lists(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        for ct in ConstraintType:
            req = EvidenceRequirements.get_requirements(ct)
            assert len(req["preferred"]) > 0
            assert len(req["acceptable"]) > 0
            assert len(req["sources"]) > 0


class TestGetMinimumConfidence:
    """Tests for EvidenceRequirements.get_minimum_confidence() method."""

    def test_statistic_highest_threshold(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        assert (
            EvidenceRequirements.get_minimum_confidence(
                ConstraintType.STATISTIC
            )
            == 0.8
        )

    def test_event_moderate_threshold(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        assert (
            EvidenceRequirements.get_minimum_confidence(ConstraintType.EVENT)
            == 0.7
        )

    def test_property_threshold(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        assert (
            EvidenceRequirements.get_minimum_confidence(ConstraintType.PROPERTY)
            == 0.6
        )

    def test_name_pattern_lowest_explicit_threshold(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        assert (
            EvidenceRequirements.get_minimum_confidence(
                ConstraintType.NAME_PATTERN
            )
            == 0.5
        )

    def test_unlisted_type_gets_default_0_6(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        assert (
            EvidenceRequirements.get_minimum_confidence(ConstraintType.LOCATION)
            == 0.6
        )

    def test_all_thresholds_between_0_and_1(self):
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        for ct in ConstraintType:
            threshold = EvidenceRequirements.get_minimum_confidence(ct)
            assert 0.0 <= threshold <= 1.0

    def test_statistic_higher_than_name_pattern(self):
        """Statistical claims require higher confidence than name patterns."""
        from local_deep_research.advanced_search_system.constraints.base_constraint import (
            ConstraintType,
        )
        from local_deep_research.advanced_search_system.evidence.requirements import (
            EvidenceRequirements,
        )

        stat = EvidenceRequirements.get_minimum_confidence(
            ConstraintType.STATISTIC
        )
        name = EvidenceRequirements.get_minimum_confidence(
            ConstraintType.NAME_PATTERN
        )
        assert stat > name
