"""parse_kind_prefix — IR-style `kind:name` shortcut at the input boundary."""

from backend.app.utils.tag_prefix import KNOWN_KINDS, parse_kind_prefix


def test_recognized_kinds_match_user_input_set():
    # Excluded: archive + post (system-managed), general (default for
    # un-prefixed input), artist (retired in FC-2d-vii-c — first-class
    # entities now), meta + rating (retired as user-typeable per
    # operator 2026-05-26).
    assert KNOWN_KINDS == frozenset({
        "character", "fandom", "series",
    })


def test_character_prefix_parsed():
    assert parse_kind_prefix("character:Saber") == ("character", "Saber")


def test_case_insensitive_prefix():
    assert parse_kind_prefix("Character:Saber") == ("character", "Saber")
    assert parse_kind_prefix("CHARACTER:Saber") == ("character", "Saber")


def test_no_prefix_returns_none_kind():
    assert parse_kind_prefix("sunset") == (None, "sunset")


def test_unknown_prefix_kept_as_literal():
    # 'http' is not a known kind — preserve the literal text.
    assert parse_kind_prefix("http://example.com") == (None, "http://example.com")


def test_retired_prefixes_kept_as_literal():
    # `artist:`, `meta:`, `rating:` are no longer recognized — they
    # parse as literal text so the operator's input is preserved (and
    # serves as a nudge to use the appropriate dedicated UI instead).
    assert parse_kind_prefix("artist:Eric") == (None, "artist:Eric")
    assert parse_kind_prefix("meta:wide") == (None, "meta:wide")
    assert parse_kind_prefix("rating:safe") == (None, "rating:safe")


def test_whitespace_stripped():
    assert parse_kind_prefix("series: Bleach ") == ("series", "Bleach")
    assert parse_kind_prefix("  sunset  ") == (None, "sunset")


def test_empty_string():
    assert parse_kind_prefix("") == (None, "")


def test_just_colon():
    # Empty prefix → "" not in KNOWN_KINDS → falls through to (None, "...")
    assert parse_kind_prefix(":foo") == (None, ":foo")
