"""
Behavioral tests for base_evidence module.

Tests EvidenceType enum with base_confidence property and Evidence dataclass.
"""


class TestEvidenceTypeEnum:
    """Tests for EvidenceType enum values."""

    def test_direct_statement_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.DIRECT_STATEMENT.value == "direct_statement"

    def test_official_record_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.OFFICIAL_RECORD.value == "official_record"

    def test_research_finding_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.RESEARCH_FINDING.value == "research_finding"

    def test_news_report_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.NEWS_REPORT.value == "news_report"

    def test_statistical_data_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.STATISTICAL_DATA.value == "statistical_data"

    def test_inference_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.INFERENCE.value == "inference"

    def test_correlation_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.CORRELATION.value == "correlation"

    def test_speculation_exists(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.SPECULATION.value == "speculation"

    def test_has_eight_types(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert len(EvidenceType) == 8


class TestEvidenceTypeBaseConfidence:
    """Tests for EvidenceType.base_confidence property."""

    def test_direct_statement_highest_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.DIRECT_STATEMENT.base_confidence == 0.95

    def test_official_record_high_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.OFFICIAL_RECORD.base_confidence == 0.90

    def test_research_finding_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.RESEARCH_FINDING.base_confidence == 0.85

    def test_statistical_data_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.STATISTICAL_DATA.base_confidence == 0.85

    def test_news_report_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.NEWS_REPORT.base_confidence == 0.75

    def test_inference_moderate_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.INFERENCE.base_confidence == 0.50

    def test_correlation_low_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.CORRELATION.base_confidence == 0.30

    def test_speculation_lowest_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert EvidenceType.SPECULATION.base_confidence == 0.10

    def test_confidence_ordering(self):
        """Higher reliability evidence types have higher confidence."""
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        assert (
            EvidenceType.DIRECT_STATEMENT.base_confidence
            > EvidenceType.OFFICIAL_RECORD.base_confidence
            > EvidenceType.NEWS_REPORT.base_confidence
            > EvidenceType.INFERENCE.base_confidence
            > EvidenceType.CORRELATION.base_confidence
            > EvidenceType.SPECULATION.base_confidence
        )

    def test_all_confidences_between_0_and_1(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            EvidenceType,
        )

        for et in EvidenceType:
            assert 0.0 <= et.base_confidence <= 1.0


class TestEvidenceInit:
    """Tests for Evidence dataclass initialization."""

    def test_basic_construction(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(
            claim="test claim",
            type=EvidenceType.DIRECT_STATEMENT,
            source="wiki",
        )
        assert e.claim == "test claim"
        assert e.type == EvidenceType.DIRECT_STATEMENT
        assert e.source == "wiki"

    def test_auto_confidence_from_type(self):
        """When confidence is 0.0 (default), auto-set from type.base_confidence."""
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.OFFICIAL_RECORD, source="s")
        assert e.confidence == 0.90

    def test_custom_confidence_preserved(self):
        """When confidence is explicitly provided (non-zero), it is preserved."""
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(
            claim="c",
            type=EvidenceType.OFFICIAL_RECORD,
            source="s",
            confidence=0.42,
        )
        assert e.confidence == 0.42

    def test_reasoning_defaults_none(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.INFERENCE, source="s")
        assert e.reasoning is None

    def test_raw_text_defaults_none(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.INFERENCE, source="s")
        assert e.raw_text is None

    def test_timestamp_is_set(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.INFERENCE, source="s")
        assert isinstance(e.timestamp, str)
        assert len(e.timestamp) > 0

    def test_metadata_defaults_empty_dict(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.INFERENCE, source="s")
        assert e.metadata == {}

    def test_speculation_auto_confidence(self):
        from local_deep_research.advanced_search_system.evidence.base_evidence import (
            Evidence,
            EvidenceType,
        )

        e = Evidence(claim="c", type=EvidenceType.SPECULATION, source="s")
        assert e.confidence == 0.10
