"""on_call.py: your turn, add an ESCALATION LADDER.

A page is only useful if someone answers it. In real on-call, if the first responder (L1) does not
acknowledge a sev1 within a few minutes, it must escalate to L2, then to L3, so a missed page becomes
someone else's page, not a missed outage. A sev3 ticket should never page anyone.

Steps:
  1. Finish `escalate` below so it returns who should be paged given the severity, how long the page
     has gone unacknowledged, and the ladder of responders.
  2. A sev1 unacknowledged past each threshold climbs the ladder; a sev3 never pages.
  3. Run:  python on_call.py

The worked alerting logic (burn rate, two-window alert, severity) is in ../solution/oncall.py.
"""

LADDER = ["L1-primary", "L2-secondary", "L3-manager"]

# Minutes of no-acknowledgement before climbing to the next rung.
ESCALATE_AFTER = [0, 5, 15]   # page L1 immediately, L2 after 5 min, L3 after 15 min


def escalate(severity: str, minutes_unacked: int, ladder=LADDER, thresholds=ESCALATE_AFTER):
    """Return the responder who should currently be paged, or None if no page is warranted.

    Rules to implement:
      - sev3 (and anything that is not sev1/sev2) never pages -> return None.
      - Otherwise walk the thresholds: the responder is the highest rung whose ESCALATE_AFTER
        threshold has been reached by `minutes_unacked` (e.g. 0 min -> L1, 5 min -> L2, 15 min -> L3).
      - Never climb past the top of the ladder.
    """
    # TODO: if severity not in ("sev1", "sev2"): return None
    # TODO: find the highest index i where minutes_unacked >= thresholds[i], clamped to len(ladder)-1
    # TODO: return ladder[i]
    raise NotImplementedError("implement the escalation ladder")


if __name__ == "__main__":
    print("sev3 at 30 min ->", escalate("sev3", 30))      # expect: None (tickets never page)
    for m in (0, 4, 5, 14, 15, 60):
        print(f"sev1 unacked {m:>2} min ->", escalate("sev1", m))
    # Goal: 0-4 min -> L1-primary, 5-14 -> L2-secondary, 15+ -> L3-manager.
