"""Tests for type_utils.py"""


class TestToBool:
    """Tests for to_bool function."""

    def test_bool_true(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(True) is True

    def test_bool_false(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(False) is False

    def test_string_true(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("true") is True
        assert to_bool("True") is True
        assert to_bool("TRUE") is True

    def test_string_false(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("false") is False
        assert to_bool("False") is False

    def test_string_yes(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("yes") is True
        assert to_bool("Yes") is True

    def test_string_no(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("no") is False
        assert to_bool("No") is False

    def test_string_one(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("1") is True

    def test_string_zero(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("0") is False

    def test_int_truthy(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(1) is True
        assert to_bool(42) is True

    def test_int_falsy(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(0) is False

    def test_none_returns_default(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool(None, default=True) is True
        assert to_bool(None, default=False) is False

    def test_empty_string_returns_default(self):
        from local_deep_research.utilities.type_utils import to_bool

        assert to_bool("", default=False) is False

    def test_invalid_string_returns_false(self):
        from local_deep_research.utilities.type_utils import to_bool

        # Invalid/unrecognized strings return False (not the default)
        # The default parameter is only used when value is None
        assert to_bool("invalid", default=False) is False
        assert to_bool("maybe", default=True) is False
        assert to_bool("random", default=True) is False
