"""Backwards-compat shim — public API delegates to ``aborist.concepts``.

The actual data lived as hand-curated frozensets in this module
through April 2026 (commit c6182ae) and one entry was added in
2026-05-01 (commit bde1bd6 — mind/brain-tech group). 2026-05-01 the
data layer moved to a per-shard ``concept_relations`` SQLite table
(see aborist/concepts/__init__.py for the rationale).

This shim preserves the call-site signatures `query.py` already uses
(``synonym_expand(qtokens)`` & ``rivalry_excluded(qtokens, compare_phrasing=...)``)
so the migration is a pure-implementation swap with no API change.

The new implementation needs a ``shards_dir`` to know which shards to
walk. The runtime threads it through query() already (kwarg passes
through), so the bridging happens here: callers that don't pass
``shards_dir`` get the empty-set degenerate behavior, which matches
the legacy code path when no synonym/rivalry was applicable.
"""

from __future__ import annotations

from pathlib import Path

from aborist.concepts.query import (
    has_compare_phrasing,
    rivalry_excluded as _rivalry_excluded_impl,
    synonym_expand as _synonym_expand_impl,
)

__all__ = ["has_compare_phrasing", "rivalry_excluded", "synonym_expand"]


def synonym_expand(
    tokens: set[str],
    *,
    shards_dir: Path | str | None = None,
) -> set[str]:
    """Add all synonym-group members for any token that hits a group.

    When ``shards_dir`` is None (the legacy two-arg call shape), returns
    the input tokens unchanged. The runtime threads ``shards_dir``
    through retrieval — call sites that pass it get the corpus-derived
    expansion; tests that don't get a no-op.
    """
    if shards_dir is None:
        return set(tokens)
    return _synonym_expand_impl(tokens, shards_dir=shards_dir)


def rivalry_excluded(
    tokens: set[str],
    compare_phrasing: bool = False,
    *,
    shards_dir: Path | str | None = None,
) -> set[str]:
    """Tokens whose presence in a doc title means EXCLUDE that doc.

    Same call shape as the legacy positional (tokens, compare_phrasing)
    so existing callers don't break. New calls pass ``shards_dir``
    via kwarg to enable corpus-derived rivalries.
    """
    if shards_dir is None:
        return set()
    return _rivalry_excluded_impl(
        tokens,
        shards_dir=shards_dir,
        compare_phrasing=compare_phrasing,
    )
