"""US-001 (PRD 5.18) — pre-filtru determinist non-operatii (NUL).

Masuratoarea k-NN (memorie test-precizie-knn-embeddings) arata recall NUL doar 64%:
gunoiul evident (ITP, plata, discount, nr. inmatriculare, tractare) scapa ca OE-1.
Un pre-filtru determinist il marcheaza NUL INAINTE de k-NN.

Garantie non-negociabila (AC): ZERO fals-pozitiv pe operatii reale. Regulile
text/regex au fost calibrate pe `docs/operatii-service/*.csv` (vezi sesiunea de
implementare): triggerele ambigue (TRACTARE, NR INMATRICULARE/placuta) sunt
ECRANATE de un context de piesa/operatie (D/R, CARLIG, CAPAC, INLOCUIT...).
"""

from __future__ import annotations

from app.mapping import prefiltru_nul


def test_itp_e_nul():
    assert prefiltru_nul("13 X ITP") is True
    assert prefiltru_nul("11XITP") is True          # glue fara spatii
    assert prefiltru_nul("ITP") is True
    assert prefiltru_nul("2 X ITP") is True


def test_plata_discount_nul():
    assert prefiltru_nul("DISCOUNT FIDELITATE 10%") is True
    assert prefiltru_nul("REDUCERE COMERCIALA") is True
    assert prefiltru_nul("ACHITAT DE CONF.URBAN") is True
    assert prefiltru_nul("PLATA AVANS") is True
    assert prefiltru_nul("TAXA DE MEDIU") is True


def test_nr_inmatriculare_nul():
    assert prefiltru_nul("NR INMATRICULARE") is True
    assert prefiltru_nul("NUMAR INMATRICULARE") is True
    assert prefiltru_nul("B 123 ABC") is True       # pattern placuta standalone
    assert prefiltru_nul("CT 44 MKY") is True


def test_tractare_serviciu_nul():
    # Serviciul de tractare (rmorca) = non-operatie de service.
    assert prefiltru_nul("TRACTARE CTA-SLOBOZIA") is True
    assert prefiltru_nul("TRACTARE 100 KM") is True


def test_operatie_reala_nu_e_nul():
    # Punctul critic: trigger ambiguu intr-un context de piesa reala -> NU e NUL.
    assert prefiltru_nul("INLOCUIT PLACUTE FRANA") is False
    assert prefiltru_nul("D/R CARLIG TRACTARE") is False        # carlig = piesa, nu serviciu
    assert prefiltru_nul("D/R CAPAC TRACTARE BARA SPATE") is False
    assert prefiltru_nul("D/R NR INMATRICULARE") is False       # suport placuta = piesa
    assert prefiltru_nul("D/R ELECTROMOTOR CT 44 MKY") is False  # placuta lipita la o operatie reala


def test_zero_fals_pozitiv_pe_set_operatii_reale():
    """AC: zero fals-pozitiv pe un set de 20 operatii reale (din docs/operatii-service)."""
    reale = [
        "REVIZIE", "SCHIMB ULEI MOTOR", "INLOCUIT PLACUTE FRANA FATA",
        "D/R BARA FATA", "VOPSIT USA DR FATA", "INLOCUIT FILTRU AER",
        "AERISIT INSTALATIE FRANA", "INLOCUIT AMORTIZOR SPATE", "ABSORBANT SOC BARA SPATE",
        "INLOCUIT CUREA DISTRIBUTIE", "REGLAT FARURI", "INLOCUIT BUJII",
        "REPARAT ARIPA FATA DR", "INLOCUIT DISCURI FRANA", "GRESAT PLANETARA",
        "INLOCUIT RULMENT ROATA", "MONTAT ANVELOPE", "INLOCUIT BATERIE",
        "DIAGNOZA COMPUTERIZATA", "INLOCUIT CONTACT PORNIRE",
    ]
    for op in reale:
        assert prefiltru_nul(op) is False, f"fals-pozitiv pe operatie reala: {op!r}"


def test_input_gol_nu_e_nul():
    assert prefiltru_nul("") is False
    assert prefiltru_nul(None) is False  # type: ignore[arg-type]
