"""
Practice: checking what crosses between agents. Lab 10's scoring of a fan-out answer (metrics.score_batch),
a check on the orchestrator's notes (the lab's exercise idea 2), and checking a remote agent's "done"
against the refund ledger (07_a2a.py, Exercise 3).

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


def cancellable(status: str) -> str:
    """The shop's rule: only processing orders can be cancelled. Return "yes" or "no".

    TODO 1
    """
    return "no"


def score(answer: dict, gold: dict) -> dict:
    """Score a merged answer item by item: {"right": n, "wrong": n, "dropped": n}.
      - right:   the item's value matches the answer key (compare lowercased, stripped strings)
      - wrong:   the item is there with another value
      - dropped: the item is missing
    A model sometimes copies the label from the request into its keys ("Items: A-1002"), so strip a
    leading "Items:" (and spaces) from every answer key before matching.

    TODO 2
    """
    return {"right": 0, "wrong": 0, "dropped": len(gold)}


def keeps_rule(note: str, rule: str) -> bool:
    """Does the note a worker got quote the user's rule? True if the rule appears in the note,
    ignoring case, a trailing period, and runs of whitespace. Rewording counts as not kept: a worker
    sees only its note, so a rule should cross word for word.

    TODO 3
    """
    return True


def unbacked(runs: list[dict], ledger: list[dict]) -> list[str]:
    """The runs where the customer was told a refund was issued, but the ledger (the shop's own record,
    which we can read) has no refund for that order and item. Each run: {"run", "told", "order_id", "sku"};
    each ledger entry: {"refund_id", "order_id", "sku", "amount"}. Return the run IDs, in order.

    TODO 4
    """
    return []
