"""
Practice: score an AI code reviewer like a classifier, the way Lab 03 compares one model in three
harnesses (a single prompt, an agent with repo tools, and PR-Agent) on the same 30 planted bugs,
three runs each. You'll count recall per run and for the pooled runs, compare two reviewers bug by
bug with a paired bootstrap, compute precision, and decide when a test proves a bug.

Fill in the TODOs, then run the tests:
    pytest test_harness_practice.py        (locally)
or press "Run tests" on the chapter page.
"""
import random


def recall_per_run(found: list[list[int]]) -> list[int]:
    """found[i][r] is 1 if run r found planted bug i, else 0 (every bug has the same number of runs).
    Return, for each run, how many bugs it found."""
    # TODO
    raise NotImplementedError


def pooled(found: list[list[int]]) -> int:
    """How many bugs at least one run found: the recall of reading all the runs' comments together."""
    # TODO
    raise NotImplementedError


def only_by(a: list[list[int]], b: list[list[int]]) -> tuple[int, int]:
    """Two reviewers on the same bugs, in the same order. Return (bugs reviewer a found in at least one
    run and b never did, bugs b found in at least one run and a never did)."""
    # TODO
    raise NotImplementedError


def paired_bootstrap(a: list[list[int]], b: list[list[int]], iterations: int = 2000,
                     seed: int = 0) -> tuple[float, float, float]:
    """Difference in recall, b minus a, with a 95% interval, paired on the same bugs.

    1. For each bug, each reviewer's score is the share of its runs that found it (0, 1/3, 2/3 or 1).
    2. diffs[i] = b's score - a's score for bug i. The point estimate is the mean of diffs.
    3. rng = random.Random(seed). Repeat `iterations` times: draw n = len(diffs) indexes with
       rng.randrange(n) (with replacement) and take the mean of those diffs.
    4. Sort the resampled means. Return (point, boots[int(0.025 * iterations)],
       boots[int(0.975 * iterations) - 1]).
    Resampling bugs as pairs keeps the fact that a hard bug is hard for both reviewers."""
    # TODO
    raise NotImplementedError


def precision(right: int, unmatched: int) -> float:
    """right: bug comments that match a planted bug or a known issue. unmatched: bug comments that
    match nothing. Return the share of bug comments that were right (0.0 if there are none)."""
    # TODO
    raise NotImplementedError


def proven(on_pr: str, with_fix: str) -> bool:
    """A proof test is run twice: on the pull request, and with a fix applied. Each result is "fails"
    or "passes". The bug is proven only if the test fails on the PR and passes with the fix: passing
    with the fix shows the test fails because of this bug, not a typo or another bug nearby."""
    # TODO
    raise NotImplementedError
