"""Tests for enums module."""

from enum import Enum

import pytest

from local_deep_research.utilities.enums import (
    KnowledgeAccumulationApproach,
    SearchMode,
)


class TestKnowledgeAccumulationApproach:
    """Tests for KnowledgeAccumulationApproach enum."""

    def test_is_enum(self):
        """Should be an Enum class."""
        assert issubclass(KnowledgeAccumulationApproach, Enum)

    def test_has_question_value(self):
        """Should have QUESTION value."""
        assert KnowledgeAccumulationApproach.QUESTION.value == "QUESTION"

    def test_has_iteration_value(self):
        """Should have ITERATION value."""
        assert KnowledgeAccumulationApproach.ITERATION.value == "ITERATION"

    def test_has_no_knowledge_value(self):
        """Should have NO_KNOWLEDGE value."""
        assert (
            KnowledgeAccumulationApproach.NO_KNOWLEDGE.value == "NO_KNOWLEDGE"
        )

    def test_has_max_nr_of_characters_value(self):
        """Should have MAX_NR_OF_CHARACTERS value."""
        assert (
            KnowledgeAccumulationApproach.MAX_NR_OF_CHARACTERS.value
            == "MAX_NR_OF_CHARACTERS"
        )

    def test_all_values_are_strings(self):
        """All values should be strings."""
        for member in KnowledgeAccumulationApproach:
            assert isinstance(member.value, str)

    def test_can_access_by_name(self):
        """Should be able to access members by name."""
        assert (
            KnowledgeAccumulationApproach["QUESTION"]
            == KnowledgeAccumulationApproach.QUESTION
        )

    def test_can_access_by_value(self):
        """Should be able to access members by value."""
        assert (
            KnowledgeAccumulationApproach("QUESTION")
            == KnowledgeAccumulationApproach.QUESTION
        )

    def test_invalid_value_raises_error(self):
        """Should raise ValueError for invalid value."""
        with pytest.raises(ValueError):
            KnowledgeAccumulationApproach("INVALID")

    def test_member_count(self):
        """Should have exactly 4 members."""
        assert len(KnowledgeAccumulationApproach) == 4


class TestSearchMode:
    """Tests for SearchMode enum."""

    def test_is_enum(self):
        """Should be an Enum class."""
        assert issubclass(SearchMode, Enum)

    def test_has_all_value(self):
        """Should have ALL value."""
        assert SearchMode.ALL.value == "all"

    def test_has_scientific_value(self):
        """Should have SCIENTIFIC value."""
        assert SearchMode.SCIENTIFIC.value == "scientific"

    def test_all_values_are_lowercase(self):
        """All values should be lowercase strings."""
        for member in SearchMode:
            assert isinstance(member.value, str)
            assert member.value == member.value.lower()

    def test_can_access_by_name(self):
        """Should be able to access members by name."""
        assert SearchMode["ALL"] == SearchMode.ALL
        assert SearchMode["SCIENTIFIC"] == SearchMode.SCIENTIFIC

    def test_can_access_by_value(self):
        """Should be able to access members by value."""
        assert SearchMode("all") == SearchMode.ALL
        assert SearchMode("scientific") == SearchMode.SCIENTIFIC

    def test_invalid_value_raises_error(self):
        """Should raise ValueError for invalid value."""
        with pytest.raises(ValueError):
            SearchMode("invalid")

    def test_member_count(self):
        """Should have exactly 2 members."""
        assert len(SearchMode) == 2

    def test_has_docstring(self):
        """SearchMode should have a docstring."""
        assert SearchMode.__doc__ is not None
        assert "Search mode" in SearchMode.__doc__


class TestEnumComparison:
    """Tests for enum comparison behavior."""

    def test_same_members_are_equal(self):
        """Same enum members should be equal."""
        assert (
            KnowledgeAccumulationApproach.QUESTION
            == KnowledgeAccumulationApproach.QUESTION
        )

    def test_different_members_not_equal(self):
        """Different enum members should not be equal."""
        assert (
            KnowledgeAccumulationApproach.QUESTION
            != KnowledgeAccumulationApproach.ITERATION
        )

    def test_member_not_equal_to_string(self):
        """Enum member should not be equal to its string value directly."""
        assert KnowledgeAccumulationApproach.QUESTION != "QUESTION"

    def test_can_use_in_dict_keys(self):
        """Enum members can be used as dictionary keys."""
        config = {
            KnowledgeAccumulationApproach.QUESTION: "question_handler",
            KnowledgeAccumulationApproach.ITERATION: "iteration_handler",
        }
        assert (
            config[KnowledgeAccumulationApproach.QUESTION] == "question_handler"
        )

    def test_can_use_in_set(self):
        """Enum members can be used in sets."""
        modes = {SearchMode.ALL, SearchMode.SCIENTIFIC}
        assert SearchMode.ALL in modes
        assert len(modes) == 2
