"""Legal-principles terminology — the single source for what a principle is CALLED (#152).

chaim 2026-06-19: "הלכה" was the wrong umbrella. The corpus holds **עקרונות
משפטיים** (legal principles); the term for one depends on its SOURCE:

  • binding higher court (מחוזי/עליון)      → "הלכה"          (binding precedent)
  • appeals committee (internal_committee)  → "כלל פרשני"     (interpretive rule —
                                              the committee applies law, never makes it)
  • non-binding external (persuasive)       → "עיקרון"        (persuasive principle)

The class is derived from where a principle was FIRST established
(canonical_halachot.first_established_in → case_law.source_kind/is_binding), so no
new column is needed. UI/tools call :func:`label` instead of hardcoding "הלכה".
"""
from __future__ import annotations

UMBRELLA = "עקרונות משפטיים"

CLASS_HALACHA = "halacha"
CLASS_INTERPRETIVE_RULE = "interpretive_rule"
CLASS_PRINCIPLE = "principle"

_LABEL = {
    CLASS_HALACHA: "הלכה",
    CLASS_INTERPRETIVE_RULE: "כלל פרשני",
    CLASS_PRINCIPLE: "עיקרון",
}


def principle_class(source_kind: str | None, is_binding: bool | None) -> str:
    """Map a source to its principle class (stable key, not display text)."""
    if source_kind == "internal_committee":
        return CLASS_INTERPRETIVE_RULE
    if is_binding:
        return CLASS_HALACHA
    return CLASS_PRINCIPLE


def label(source_kind: str | None, is_binding: bool | None) -> str:
    """Hebrew display term for a principle from this source (#152)."""
    return _LABEL[principle_class(source_kind, is_binding)]


def label_for_class(cls: str) -> str:
    return _LABEL.get(cls, _LABEL[CLASS_PRINCIPLE])
