"""120-day DOS-age gate. CO Medicaid's timely-filing window is 120 days from DOS."""
from datetime import date
from decimal import Decimal
from cyclone.rebill.timely_filing import timely_filing_decision, FILING_WINDOW_DAYS


def test_visit_within_window_is_rebillable():
    decision = timely_filing_decision(
        dos=date(2026, 6, 1), as_of=date(2026, 7, 7), override=False
    )
    assert decision.rebillable is True


def test_visit_past_window_excluded_by_default():
    decision = timely_filing_decision(
        dos=date(2026, 1, 1), as_of=date(2026, 7, 7), override=False
    )
    assert decision.rebillable is False
    assert decision.days_old == 187


def test_visit_at_exact_120_days_inclusive():
    decision = timely_filing_decision(
        dos=date(2026, 3, 9), as_of=date(2026, 7, 7), override=False
    )
    # 2026-03-09 → 2026-07-07 = 120 days
    assert decision.days_old == 120
    assert decision.rebillable is True


def test_override_flag_relaxes_the_gate():
    decision = timely_filing_decision(
        dos=date(2026, 1, 1), as_of=date(2026, 7, 7), override=True
    )
    assert decision.rebillable is True


def test_window_constant_is_120():
    assert FILING_WINDOW_DAYS == 120
