"""Tests for SuggestionLevel, format_suggestions, and parse_tolerate_node_keys."""

import pytest

from valn8n_lib.types import SuggestionLevel, format_suggestions, parse_tolerate_node_keys


class TestFormatSuggestions:
    def test_none_returns_empty(self) -> None:
        assert format_suggestions({"a", "b", "c"}, SuggestionLevel.NONE) == ""

    def test_full_returns_all_sorted(self) -> None:
        result = format_suggestions({"c", "a", "b"}, SuggestionLevel.FULL)
        assert result == "; valid values: a, b, c"

    def test_short_under_five(self) -> None:
        result = format_suggestions({"x", "y"}, SuggestionLevel.SHORT)
        assert result == "; valid values: x, y"

    def test_short_truncates_at_five(self) -> None:
        items = {"a", "b", "c", "d", "e", "f", "g"}
        result = format_suggestions(items, SuggestionLevel.SHORT)
        assert result.startswith("; valid values: a, b, c, d, e")
        assert "(7 total)" in result

    def test_short_exactly_five(self) -> None:
        items = {"a", "b", "c", "d", "e"}
        result = format_suggestions(items, SuggestionLevel.SHORT)
        assert result == "; valid values: a, b, c, d, e"
        assert "total" not in result

    def test_list_preserves_order(self) -> None:
        result = format_suggestions(["z", "a", "m"], SuggestionLevel.FULL)
        assert result == "; valid values: z, a, m"

    def test_set_sorts(self) -> None:
        result = format_suggestions({"z", "a", "m"}, SuggestionLevel.FULL)
        assert result == "; valid values: a, m, z"


class TestParseTolerateNodeKeys:
    def test_empty_string_returns_empty_frozenset(self) -> None:
        assert parse_tolerate_node_keys("") == frozenset()

    def test_comma_separated_values(self) -> None:
        assert parse_tolerate_node_keys("meta,stickyNote") == frozenset({"meta", "stickyNote"})

    def test_whitespace_trimmed(self) -> None:
        assert parse_tolerate_node_keys(" meta , stickyNote ") == frozenset({"meta", "stickyNote"})

    def test_wildcard_returns_none(self) -> None:
        assert parse_tolerate_node_keys("*") is None

    def test_wildcard_mixed_raises(self) -> None:
        with pytest.raises(ValueError, match="Cannot mix"):
            parse_tolerate_node_keys("*,meta")
