"""T-TGL-011 / T-TGL-012: the blocked-reason predicate — each required
field nulled in turn flags its EXACT message (first-missing-field order),
and a fully-resolved entry is not blocked. Pure function; no DB.
"""

from app.services.reporting.filters import ELIGIBILITY_MESSAGE_ORDER, blocked_reason

_COMPLETE = {
    "worker": "Adi",
    "operator": "PlusROI",
    "client": "Brentwood",
    "project": "Website",
    "description": "did the thing",
    "end_at": "2026-05-20 10:00:00",
    "source_user_email": "info@adipramono.com",
}


def test_t_tgl_012_fully_resolved_is_not_blocked():
    assert blocked_reason(**_COMPLETE) is None


def test_t_tgl_011_each_missing_field_flags_its_exact_message():
    # First-missing-field wins, in the pinned ELIGIBILITY order.
    for field, message in ELIGIBILITY_MESSAGE_ORDER:
        args = dict(_COMPLETE)
        args[field] = None
        assert blocked_reason(**args) == message, field


def test_t_tgl_011_order_first_missing_wins():
    # worker AND end_at both missing -> worker (earlier in the order) wins.
    args = dict(_COMPLETE, worker=None, end_at=None)
    assert blocked_reason(**args) == ELIGIBILITY_MESSAGE_ORDER[0][1]
