"""
Behavioral tests for type_utils module.

Tests the to_bool function for boolean conversion.
"""


class TestToBoolBooleanInput:
    """Tests for boolean input handling."""

    def test_true_returns_true(self):
        """Boolean True returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(True) is True

    def test_false_returns_false(self):
        """Boolean False returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(False) is False


class TestToBoolStringTruthyValues:
    """Tests for string truthy values."""

    def test_true_string_returns_true(self):
        """String 'true' returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("true") is True

    def test_TRUE_uppercase_returns_true(self):
        """String 'TRUE' (uppercase) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("TRUE") is True

    def test_True_mixed_case_returns_true(self):
        """String 'True' (mixed case) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("True") is True

    def test_1_string_returns_true(self):
        """String '1' returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("1") is True

    def test_yes_returns_true(self):
        """String 'yes' returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("yes") is True

    def test_YES_uppercase_returns_true(self):
        """String 'YES' (uppercase) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("YES") is True

    def test_on_returns_true(self):
        """String 'on' returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("on") is True

    def test_ON_uppercase_returns_true(self):
        """String 'ON' (uppercase) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("ON") is True

    def test_enabled_returns_true(self):
        """String 'enabled' returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("enabled") is True

    def test_ENABLED_uppercase_returns_true(self):
        """String 'ENABLED' (uppercase) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("ENABLED") is True


class TestToBoolStringFalsyValues:
    """Tests for string falsy values."""

    def test_false_string_returns_false(self):
        """String 'false' returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("false") is False

    def test_FALSE_uppercase_returns_false(self):
        """String 'FALSE' (uppercase) returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("FALSE") is False

    def test_0_string_returns_false(self):
        """String '0' returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("0") is False

    def test_no_returns_false(self):
        """String 'no' returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("no") is False

    def test_off_returns_false(self):
        """String 'off' returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("off") is False

    def test_disabled_returns_false(self):
        """String 'disabled' returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("disabled") is False

    def test_empty_string_returns_false(self):
        """Empty string returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("") is False

    def test_whitespace_returns_false(self):
        """Whitespace-only string returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("   ") is False

    def test_random_string_returns_false(self):
        """Random string returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("random") is False

    def test_maybe_returns_false(self):
        """String 'maybe' returns False (not a truthy value)."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("maybe") is False


class TestToBoolNoneValues:
    """Tests for None value handling."""

    def test_none_returns_default_false(self):
        """None returns default False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(None) is False

    def test_none_with_default_true(self):
        """None with default=True returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(None, default=True) is True

    def test_none_with_default_false(self):
        """None with default=False returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(None, default=False) is False


class TestToBoolIntegerValues:
    """Tests for integer value handling."""

    def test_1_returns_true(self):
        """Integer 1 returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(1) is True

    def test_0_returns_false(self):
        """Integer 0 returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(0) is False

    def test_positive_integer_returns_true(self):
        """Positive integer returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(42) is True

    def test_negative_integer_returns_true(self):
        """Negative integer returns True (non-zero)."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(-1) is True


class TestToBoolFloatValues:
    """Tests for float value handling."""

    def test_1_0_returns_true(self):
        """Float 1.0 returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(1.0) is True

    def test_0_0_returns_false(self):
        """Float 0.0 returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(0.0) is False

    def test_positive_float_returns_true(self):
        """Positive float returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(3.14) is True

    def test_small_positive_float_returns_true(self):
        """Small positive float returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(0.001) is True

    def test_negative_float_returns_true(self):
        """Negative float returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(-1.5) is True


class TestToBoolCollectionValues:
    """Tests for collection value handling."""

    def test_empty_list_returns_false(self):
        """Empty list returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool([]) is False

    def test_non_empty_list_returns_true(self):
        """Non-empty list returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool([1, 2, 3]) is True

    def test_empty_dict_returns_false(self):
        """Empty dict returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool({}) is False

    def test_non_empty_dict_returns_true(self):
        """Non-empty dict returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool({"key": "value"}) is True

    def test_empty_set_returns_false(self):
        """Empty set returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(set()) is False

    def test_non_empty_set_returns_true(self):
        """Non-empty set returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool({1, 2, 3}) is True

    def test_empty_tuple_returns_false(self):
        """Empty tuple returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(()) is False

    def test_non_empty_tuple_returns_true(self):
        """Non-empty tuple returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool((1, 2, 3)) is True


class TestToBoolEdgeCases:
    """Tests for edge cases."""

    def test_whitespace_true_variant(self):
        """'  true  ' (with whitespace) is stripped and converted."""
        from local_deep_research.utilities.type_utils import to_bool

        result = to_bool("  true  ")
        assert result is True

    def test_tRuE_mixed_case(self):
        """'tRuE' (odd case) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("tRuE") is True

    def test_yEs_mixed_case(self):
        """'yEs' (odd case) returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("yEs") is True

    def test_default_parameter_is_respected(self):
        """Default parameter affects only None."""
        from local_deep_research.utilities.type_utils import to_bool

        # Default only affects None, not other falsy values
        assert to_bool("false", default=True) is False
        assert to_bool(0, default=True) is False
        assert to_bool(None, default=True) is True


class TestToBoolObjectValues:
    """Tests for object value handling."""

    def test_object_instance_returns_true(self):
        """Object instance returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        class MyClass:
            pass

        assert to_bool(MyClass()) is True

    def test_class_with_bool_false(self):
        """Object with __bool__ returning False returns False."""
        from local_deep_research.utilities.type_utils import to_bool

        class FalsyClass:
            def __bool__(self):
                return False

        assert to_bool(FalsyClass()) is False

    def test_class_with_bool_true(self):
        """Object with __bool__ returning True returns True."""
        from local_deep_research.utilities.type_utils import to_bool

        class TruthyClass:
            def __bool__(self):
                return True

        assert to_bool(TruthyClass()) is True


class TestToBoolTypePriority:
    """Tests for type checking priority."""

    def test_bool_checked_before_string(self):
        """Boolean is returned directly, not treated as string."""
        from local_deep_research.utilities.type_utils import to_bool

        # True is not "true" string, it's boolean
        assert to_bool(True) is True
        assert to_bool(False) is False

    def test_string_true_is_string_not_bool(self):
        """String "True" is string, returned via string path."""
        from local_deep_research.utilities.type_utils import to_bool

        # "True" string should match via string check
        result = to_bool("True")
        assert result is True

    def test_none_uses_default(self):
        """None uses the default parameter."""
        from local_deep_research.utilities.type_utils import to_bool

        # None should use default
        assert to_bool(None, default=True) is True
        assert to_bool(None, default=False) is False
