"""
Practice: a difficulty router and a majority vote, measured (Lab 02, Scripts 4-5).

Fill in the TODOs, then run the tests:
    pytest test_routing_practice.py        (locally)
or press "Run tests" on the chapter page.
"""
from collections import Counter


def route(classifier_reply: str) -> str:
    """The router's first call replies with one word, HARD or EASY, but models add punctuation or
    change case. Like the lab: "hard" if the reply contains HARD (any case), otherwise "easy".

    TODO 1
    """
    return "easy"


def majority_vote(finals: list[str]) -> tuple[str, int]:
    """Self-consistency: return (winner, votes) for a list of FINAL answers.

    Like the lab, compare answers after .strip().lower(), and return the winner in that form. On a
    tie, the answer seen first wins (collections.Counter.most_common keeps first-seen order).

    TODO 2
    """
    return finals[0], 1


def check_labels(instant_ok: list[dict[str, bool]], labels: dict[str, str]) -> dict[str, list[str]]:
    """Test your labels instead of trusting them. `instant_ok` has one dict per run: question id ->
    was the instant answer (thinking off, no steps written) right? `labels` maps id -> "hard"/"easy".

    A question needs more than an instant answer if the instant answer was wrong in ANY run.
    Return, each list sorted:
      {"should_be_hard": ids labeled easy that need more,
       "could_be_easy":  ids labeled hard whose instant answer was right in every run}

    TODO 3
    """
    return {"should_be_hard": [], "could_be_easy": []}


def easy_share(think_costs: dict[str, float], labels: dict[str, str]) -> float:
    """With thinking on everything, the share of the total cost spent on questions labeled easy:
    the most a router could ever save by sending them to an instant answer instead.

    TODO 4
    """
    return 0.0
