"""
Tests for _parse_multiselect() in settings/manager.py.

Covers list passthrough, JSON array parsing, comma-separated splitting,
and edge cases (empty, malformed, non-string/list types).
"""

from local_deep_research.settings.manager import _parse_multiselect


class TestParseMultiselect:
    """Tests for _parse_multiselect()."""

    def test_list_passthrough(self):
        assert _parse_multiselect(["a", "b"]) == ["a", "b"]

    def test_empty_list_passthrough(self):
        assert _parse_multiselect([]) == []

    def test_json_array_string(self):
        assert _parse_multiselect('["markdown","latex"]') == [
            "markdown",
            "latex",
        ]

    def test_json_array_with_spaces(self):
        assert _parse_multiselect('  ["a", "b"]  ') == ["a", "b"]

    def test_comma_separated_string(self):
        assert _parse_multiselect("markdown,latex") == ["markdown", "latex"]

    def test_comma_separated_with_spaces(self):
        assert _parse_multiselect(" a , b , c ") == ["a", "b", "c"]

    def test_single_value_no_comma(self):
        assert _parse_multiselect("markdown") == ["markdown"]

    def test_empty_string(self):
        assert _parse_multiselect("") == []

    def test_malformed_json_falls_back_to_comma(self):
        result = _parse_multiselect('["broken')
        assert result == ['["broken']

    def test_non_string_non_list_passthrough(self):
        assert _parse_multiselect(42) == 42
