"""Solution for delegation_practice.py."""
import re


def cancellable(status: str) -> str:
    return "yes" if status == "processing" else "no"


def score(answer: dict, gold: dict) -> dict:
    clean = {re.sub(r"^\s*items:\s*", "", k, flags=re.I).strip(): v for k, v in answer.items()}
    out = {"right": 0, "wrong": 0, "dropped": 0}
    for key, want in gold.items():
        if key not in clean:
            out["dropped"] += 1
        elif str(clean[key]).strip().lower() == str(want).strip().lower():
            out["right"] += 1
        else:
            out["wrong"] += 1
    return out


def _norm(text: str) -> str:
    return re.sub(r"\s+", " ", text).strip().lower().rstrip(".")


def keeps_rule(note: str, rule: str) -> bool:
    return _norm(rule) in _norm(note)


def unbacked(runs: list[dict], ledger: list[dict]) -> list[str]:
    paid = {(r["order_id"], r["sku"]) for r in ledger}
    return [r["run"] for r in runs if r["told"] and (r["order_id"], r["sku"]) not in paid]
