"""
Solution: read the hidden bill and pick the effort level (Lab 02, Scripts 1-3).
"""

PRICES = {"input": 0.20, "output": 1.25}
EFFORTS = ["none", "low", "medium", "high", "xhigh"]


def split_output(usage: dict) -> tuple[int, int, float]:
    out = usage["completion_tokens"]
    details = usage.get("completion_tokens_details") or {}
    hidden = details.get("reasoning_tokens") or 0
    return out - hidden, hidden, (hidden / out if out else 0.0)


def call_cost(usage: dict, prices: dict = PRICES) -> float:
    return (usage["prompt_tokens"] * prices["input"] + usage["completion_tokens"] * prices["output"]) / 1_000_000


def per_thousand(total_cost: float, questions: int) -> float:
    return total_cost / questions * 1000


def lowest_effort(scores: dict[str, list[int]], bar: int) -> str | None:
    for effort in EFFORTS:
        if effort in scores and all(right >= bar for right in scores[effort]):
            return effort
    return None
