"""The 12 held-out faults, each implemented once and literally from independent/author-specs.json
(DESIGN-independent.md section 5, with the rules of DESIGN-blind.md section 6).

The author wrote the specs without seeing any check. Each function follows its spec's selection rule and changes;
every reading an ambiguous phrase forced is listed in independent/JUDGEMENTS.md under the fault's id. Selections are
evaluated on the original data before any change, ids sort ascending, fewer matches than asked means all of them, and
money rounds to cents half up. Where a spec says "do nothing" if nothing qualifies, the function raises
FaultDidNotApply instead and the fault is reported as not applied. Each function edits only the build it is given (its
extracts, and its outside records only where the spec says so), in place, and returns a census of what it touched.
"""
from __future__ import annotations

import datetime as dt
from decimal import Decimal

from blind.faults import FaultDidNotApply, _by, _events, _need, _tier_on
from warehouse import generate as g

D = dt.date
LAST = g.LAST_DAY                      # 2026-09-30
SEP1, AUG1, AUG31, JUL1 = D(2026, 9, 1), D(2026, 8, 1), D(2026, 8, 31), D(2026, 7, 1)
OCT1, OCT5 = D(2026, 10, 1), D(2026, 10, 5)
FAR = D(2030, 1, 1)
__all__ = ["FAULTS", "FaultDidNotApply"]


def _month(d: D) -> D:
    return D(d.year, d.month, 1)


def _period(started: D, interval: str, day: D) -> tuple[D, D]:
    """The billing period (inclusive) containing day, anchored on the start day and clamped to month end."""
    return next((a, z) for a, z in g.card_periods(started, interval, None, FAR) if a <= day <= z)


def _proration(qty, unit: Decimal, factor: Decimal, started: D, interval: str, day: D) -> Decimal:
    b, e = _period(started, interval, day)
    return g.cents(Decimal(qty) * unit * factor * ((e - day).days + 1) / ((e - b).days + 1))


def _plan_on(changes: list[dict], day: D) -> str | None:
    before = [p for p in changes if p["effective_date"] <= day]
    return before[-1]["plan_kind"] if before else None


def _plan_throughout(changes: list[dict], start: D, end: D) -> str | None:
    """The plan kind in force on every day from start to end, or None if it changes inside that window."""
    ps = sorted(changes, key=lambda p: p["effective_date"])
    kind = _plan_on(ps, start)
    if kind is None or any(start < p["effective_date"] <= end for p in ps):
        return None
    return kind


def _invoice_totals(lines) -> dict:
    out: dict = {}
    for x in lines:
        out[x["invoice_id"]] = out.get(x["invoice_id"], Decimal(0)) + x["amount"]
    return out


def _contract_line(value: Decimal, discount, freq: str) -> Decimal:
    return g.cents(Decimal(value) * (Decimal(100) - Decimal(discount)) / Decimal(100) * g.STEP[freq] / 12)


def _seats(value: Decimal, discount) -> int:
    return max(5, int(Decimal(value) * (Decimal(100) - Decimal(discount)) / Decimal(100) / Decimal(250)))


# ------------------------------------------------------------------------------------------------- the 12 faults

def h01_bus_m_price_wrong(b: dict) -> dict:
    """H01 (systems agree): wrong monthly Business price propagated into billing."""
    t = b["tables"]
    rows = [p for p in t["card_price_list"] if p["price_id"] == "BUS-M"]
    _need(len(rows), "no BUS-M price row")
    price = rows[0]
    new = price["unit_amount"] + Decimal("1.00")
    subs = {s["subscription_id"]: s for s in t["card_subscriptions"] if s["price_id"] == "BUS-M"}
    changed = {"recurring": 0, "proration": 0, "refunds": 0}
    line_ids = set()
    for x in sorted(t["card_invoice_lines"], key=lambda x: x["line_id"]):
        s = subs.get(x["subscription_id"])
        if s is None or x["line_type"] not in ("recurring", "proration"):
            continue
        factor = 1 - Decimal(s["recurring_discount_pct"]) / 100
        if x["line_type"] == "recurring":
            x["amount"] = g.cents(Decimal(x["quantity"]) * new * factor)
        else:
            x["amount"] = _proration(x["quantity"], new, factor, s["started_on"], "monthly", x["invoice_date"])
        changed[x["line_type"]] += 1
        line_ids.add(x["line_id"])
    lines = {x["line_id"]: x for x in t["card_invoice_lines"]}
    for r in sorted(t["card_refunds"], key=lambda r: r["refund_id"]):
        if r["line_id"] in line_ids:
            x = lines[r["line_id"]]
            r["amount"] = g.cents(x["amount"] * max(0, (x["period_end"] - r["refund_date"]).days)
                                  / ((x["period_end"] - x["period_start"]).days + 1))
            changed["refunds"] += 1
    price["unit_amount"] = new
    return {"price_id": "BUS-M", "unit_amount": float(new), "subscriptions": len(subs),
            **{f"{k}_changed": v for k, v in changed.items()}}


def h02_coupons_dropped(b: dict) -> dict:
    """H02 (systems agree): lifetime coupons dropped during subscription creation."""
    t, s = b["tables"], b["sources"]
    registry = _by(s["promotion_registry"], "subscription_id")
    prices = {p["price_id"]: p for p in t["card_price_list"]}
    picks = []
    for sub in sorted(t["card_subscriptions"], key=lambda x: x["subscription_id"]):
        if not (SEP1 <= sub["started_on"] <= LAST and sub["ended_on"] is None and sub["status"] == "active"
                and sub["recurring_discount_pct"] == 20):
            continue
        if not any(r["customer_id"] == sub["customer_id"] and r["percent_off"] == 20 and r["duration"] == "forever"
                   and r["redeemed_on"] == sub["started_on"] for r in registry.get(sub["subscription_id"], [])):
            continue
        picks.append(sub)
        if len(picks) == 3:
            break
    _need(len(picks), "no subscription qualifies")
    by_sub = {x["subscription_id"]: x for x in picks}
    changed = {"recurring": 0, "proration": 0}
    for x in sorted(t["card_invoice_lines"], key=lambda x: x["line_id"]):
        sub = by_sub.get(x["subscription_id"])
        if sub is None or x["line_type"] not in ("recurring", "proration"):
            continue
        unit = prices[sub["price_id"]]["unit_amount"]
        if x["line_type"] == "recurring":
            x["amount"] = g.cents(Decimal(x["quantity"]) * unit)
        else:
            x["amount"] = _proration(x["quantity"], unit, Decimal(1), sub["started_on"],
                                     prices[sub["price_id"]]["billing_interval"], x["invoice_date"])
        changed[x["line_type"]] += 1
    for sub in picks:
        sub["recurring_discount_pct"] = 0
    return {"subscriptions": [x["subscription_id"] for x in picks], **{f"{k}_changed": v for k, v in changed.items()}}


def h03_discount_five_points_low(b: dict) -> dict:
    """H03 (systems agree): signed contract discount entered five points too low."""
    t = b["tables"]
    accounts = {a["account_id"]: a for a in t["crm_accounts"]}
    opps = {o["opportunity_id"]: o for o in t["crm_opportunities"]}
    per_account = _by(t["crm_contracts"], "account_id")
    credited = {c["contract_id"] for c in t["contract_credits"]}
    pick = None
    for c in sorted(t["crm_contracts"], key=lambda c: c["contract_id"]):
        a, o = accounts.get(c["account_id"]), opps.get(c["opportunity_id"])
        if (AUG1 <= c["signed_on"] <= AUG31 and SEP1 <= c["service_start"] <= LAST and c["service_end"] >= LAST
                and c["discount_pct"] >= 5 and a is not None and a["workspace_id"] and o is not None
                and o["stage"] == "closed_won" and c["contract_id"] not in credited and len(per_account[c["account_id"]]) == 1):
            pick = c
            break
    _need(pick is not None, "no contract qualifies")
    c = pick
    original = c["discount_pct"]
    c["discount_pct"] = original - 5
    tiers = sorted([x for x in t["crm_contract_tiers"] if x["contract_id"] == c["contract_id"]], key=lambda x: x["tier"])
    factor = (Decimal(100) - Decimal(c["discount_pct"])) / Decimal(100)
    opps[c["opportunity_id"]]["amount"] = g.cents(sum((x["annual_list_value"] * factor for x in tiers), Decimal(0)))
    invoices, lines_changed = set(), 0
    for x in sorted(t["contract_invoice_lines"], key=lambda x: x["line_id"]):
        if x["contract_id"] == c["contract_id"] and x["line_type"] == "recurring":
            tier = _tier_on(tiers, x["invoice_date"])[0]
            x["amount"] = _contract_line(tier["annual_list_value"], c["discount_pct"], c["billing_frequency"])
            invoices.add(x["invoice_id"])
            lines_changed += 1
    totals = _invoice_totals(t["contract_invoice_lines"])
    payments = 0
    for p in sorted(t["contract_payments"], key=lambda p: p["payment_id"]):
        if p["invoice_id"] in invoices:
            p["amount"] = totals[p["invoice_id"]]
            payments += 1
    w = accounts[c["account_id"]]["workspace_id"]
    snaps = 0
    for r in sorted(t["product_workspace_monthly"], key=lambda r: (r["workspace_id"], r["month_end"])):
        if r["workspace_id"] == w and c["service_start"] <= r["month_end"] <= c["service_end"]:
            tier = _tier_on(tiers, r["month_end"])[0]
            r["active_seats"] = _seats(tier["annual_list_value"], c["discount_pct"])
            snaps += 1
    return {"contract": c["contract_id"], "discount_from": original, "discount_to": c["discount_pct"],
            "recurring_lines_changed": lines_changed, "payments_changed": payments, "snapshots_changed": snaps}


def h04_ramp_year_two_copied(b: dict) -> dict:
    """H04 (systems agree): second-year ramp copied from the first year."""
    t = b["tables"]
    accounts = {a["account_id"]: a for a in t["crm_accounts"]}
    opps = {o["opportunity_id"]: o for o in t["crm_opportunities"]}
    tiers_by = _by(t["crm_contract_tiers"], "contract_id")
    credited = {c["contract_id"] for c in t["contract_credits"]}
    pick = None
    for c in sorted(t["crm_contracts"], key=lambda c: c["contract_id"]):
        ts = sorted(tiers_by.get(c["contract_id"], []), key=lambda x: x["tier"])
        a = accounts.get(c["account_id"])
        if not (c["term_months"] == 24 and _month(c["signed_on"]) == D(2025, 8, 1) and _month(c["service_start"]) == D(2025, 8, 1)
                and [x["tier"] for x in ts] == [1, 2] and ts[1]["tier_start"] <= LAST <= ts[1]["tier_end"]
                and ts[1]["annual_list_value"] > ts[0]["annual_list_value"] and a is not None and a["workspace_id"]
                and c["contract_id"] not in credited):
            continue
        pick = (c, ts)
        break
    _need(pick is not None, "no contract qualifies")
    c, ts = pick
    t1, t2 = ts
    before = t2["annual_list_value"]
    t2["annual_list_value"] = t1["annual_list_value"]
    factor = (Decimal(100) - Decimal(c["discount_pct"])) / Decimal(100)
    opps[c["opportunity_id"]]["amount"] = g.cents((t1["annual_list_value"] + t2["annual_list_value"]) * factor)
    invoices, lines_changed = set(), 0
    for x in sorted(t["contract_invoice_lines"], key=lambda x: x["line_id"]):
        if x["contract_id"] == c["contract_id"] and x["line_type"] == "recurring" and t2["tier_start"] <= x["invoice_date"] <= t2["tier_end"]:
            x["amount"] = _contract_line(t2["annual_list_value"], c["discount_pct"], c["billing_frequency"])
            invoices.add(x["invoice_id"])
            lines_changed += 1
    totals = _invoice_totals(t["contract_invoice_lines"])
    payments = 0
    for p in sorted(t["contract_payments"], key=lambda p: p["payment_id"]):
        if p["invoice_id"] in invoices:
            p["amount"] = totals[p["invoice_id"]]
            payments += 1
    w = accounts[c["account_id"]]["workspace_id"]
    snaps = 0
    for r in sorted(t["product_workspace_monthly"], key=lambda r: (r["workspace_id"], r["month_end"])):
        if r["workspace_id"] == w and t2["tier_start"] <= r["month_end"] <= t2["tier_end"]:
            r["active_seats"] = _seats(t2["annual_list_value"], c["discount_pct"])
            snaps += 1
    return {"contract": c["contract_id"], "tier2_from": float(before), "tier2_to": float(t2["annual_list_value"]),
            "recurring_lines_changed": lines_changed, "payments_changed": payments, "snapshots_changed": snaps}


def _single_paid_plan(t, w, kinds, start, end, plans) -> bool:
    return _plan_throughout(plans.get(w, []), start, end) in kinds


def h05_september_runs_doubled(b: dict) -> dict:
    """H05 (systems agree): September run counts doubled before billing."""
    t, s = b["tables"], b["sources"]
    customers = _by(t["card_customers"], "workspace_id")
    subs = _by(t["card_subscriptions"], "customer_id")
    plans = _by(t["product_plan_changes"], "workspace_id")
    usage = _by(t["usage_daily"], "workspace_id")
    events = {}
    for r in s["product_run_events_daily"]:
        if _month(r["event_date"]) == SEP1:
            events[r["workspace_id"]] = events.get(r["workspace_id"], 0) + r["run_events"]
    card_lines = _by([x for x in t["card_invoice_lines"] if x["line_type"] == "usage"], "workspace_id")
    pick = None
    for w in sorted(r["workspace_id"] for r in t["product_workspaces"]):
        covering = [x for cu in customers.get(w, []) for x in subs.get(cu["customer_id"], [])
                    if x["started_on"] <= JUL1 and x["ended_on"] is None]
        if len(covering) != 1 or not _single_paid_plan(t, w, {"self_serve"}, JUL1, LAST, plans):
            continue
        sep = [r for r in usage.get(w, []) if _month(r["usage_date"]) == SEP1]
        if not sep or not all(r["loaded_at"] < dt.datetime(2026, 10, 5) for r in sep):
            continue
        lines = [x for x in card_lines.get(w, []) if x["invoice_date"] == OCT5 and x["period_start"] == SEP1 and x["period_end"] == LAST]
        total = sum(r["runs"] for r in sep)
        if len(lines) != 1 or lines[0]["quantity"] != total or lines[0]["amount"] != g.cents(total * g.RUN_PRICE):
            continue
        if not 2 * total > events.get(w, 0):
            continue
        pick = (w, sep, lines[0])
        break
    _need(pick is not None, "no workspace qualifies")
    w, sep, line = pick
    for r in sorted(sep, key=lambda r: r["usage_id"]):
        r["runs"] = 2 * r["runs"]
    line["quantity"] = sum(r["runs"] for r in sep)
    line["amount"] = g.cents(line["quantity"] * g.RUN_PRICE)
    return {"workspace": w, "usage_rows_doubled": len(sep), "invoice_line": line["line_id"], "quantity": line["quantity"]}


def h06_current_ramp_tier_lost(b: dict) -> dict:
    """H06 (systems disagree): current ramp tier lost from the CRM extract."""
    t = b["tables"]
    contracts = {c["contract_id"]: c for c in t["crm_contracts"]}
    lines = _by([x for x in t["contract_invoice_lines"] if x["line_type"] == "recurring"], "contract_id")
    pick = None
    for x in sorted(t["crm_contract_tiers"], key=lambda x: (x["contract_id"], x["tier"])):
        c = contracts.get(x["contract_id"])
        if not (x["tier"] >= 2 and SEP1 <= x["tier_start"] <= LAST and x["tier_end"] >= LAST and x["annual_list_value"] > 0
                and c is not None and c["service_start"] <= LAST <= c["service_end"] and c["discount_pct"] < 100):
            continue
        if any(x["tier_start"] <= y["invoice_date"] <= x["tier_end"] for y in lines.get(x["contract_id"], [])):
            pick = x
            break
    _need(pick is not None, "no tier qualifies")
    t["crm_contract_tiers"].remove(pick)
    return {"tier_deleted": [pick["contract_id"], pick["tier"]], "annual_list_value": float(pick["annual_list_value"])}


def h07_seat_decrease_early(b: dict) -> dict:
    """H07 (systems disagree): next-period seat decrease applied in September."""
    t = b["tables"]
    prices = {p["price_id"]: p for p in t["card_price_list"]}
    customers = {c["customer_id"]: c for c in t["card_customers"]}
    snaps = {(r["workspace_id"], r["month_end"]): r for r in t["product_workspace_monthly"]}
    events = _events(t)
    picks = []
    for sub in sorted(t["card_subscriptions"], key=lambda x: x["subscription_id"]):
        p = prices.get(sub["price_id"])
        if not (p and p["billing_interval"] == "monthly" and sub["started_on"] <= LAST
                and (sub["ended_on"] is None or sub["ended_on"] >= LAST)):
            continue
        nxt = next(a for a, _ in g.card_periods(sub["started_on"], "monthly", None, FAR) if a > LAST)
        ev = events.get(sub["subscription_id"], [])
        for i, e in enumerate(ev):
            if not (OCT1 <= e["effective_date"] <= OCT5 and e["effective_date"] == nxt and i > 0):
                continue
            prev = ev[i - 1]
            snap = snaps.get((customers[sub["customer_id"]]["workspace_id"], LAST))
            if (e["seats_after"] < prev["seats_after"] and prev["effective_date"] < LAST
                    and not any(x["effective_date"] == LAST for x in ev) and snap is not None
                    and snap["active_seats"] == prev["seats_after"]):
                picks.append((sub["subscription_id"], e["change_id"], e))
    _need(len(picks), "no seat change qualifies: none effective 2026-10-01 to 2026-10-05")
    picks.sort(key=lambda x: (x[0], x[1]))
    e = picks[0][2]
    e["effective_date"] = LAST
    return {"change": e["change_id"], "subscription": e["subscription_id"]}


def h08_annual_optout_as_cancel(b: dict) -> dict:
    """H08 (systems disagree): annual renewal opt-out recorded as immediate cancellation."""
    t = b["tables"]
    prices = {p["price_id"]: p for p in t["card_price_list"]}
    customers = {c["customer_id"]: c for c in t["card_customers"]}
    subs_per_customer = _by(t["card_subscriptions"], "customer_id")
    plans = _by(t["product_plan_changes"], "workspace_id")
    lines = _by([x for x in t["card_invoice_lines"] if x["line_type"] == "recurring"], "subscription_id")
    s15 = D(2026, 9, 15)
    pick = None
    for sub in sorted(t["card_subscriptions"], key=lambda x: x["subscription_id"]):
        p = prices.get(sub["price_id"])
        if not (p and p["billing_interval"] == "annual" and sub["started_on"] <= s15 and sub["ended_on"] is None
                and sub["status"] == "active"):
            continue
        if not any(x["period_start"] <= s15 and x["period_end"] >= LAST for x in lines.get(sub["subscription_id"], [])):
            continue
        w = customers[sub["customer_id"]]["workspace_id"]
        if _plan_throughout(plans.get(w, []), s15, LAST) != "self_serve":
            continue
        others = [o for o in subs_per_customer[sub["customer_id"]] if o["subscription_id"] != sub["subscription_id"]
                  and o["started_on"] <= LAST and (o["ended_on"] is None or o["ended_on"] >= s15)]
        if others:
            continue
        pick = sub
        break
    _need(pick is not None, "no subscription qualifies")
    pick["ended_on"], pick["status"] = s15, "cancelled"
    return {"subscription": pick["subscription_id"]}


def h09_card_lines_duplicated(b: dict) -> dict:
    """H09 (systems disagree): recurring card invoice lines duplicated on export."""
    t = b["tables"]
    subs = {s["subscription_id"]: s for s in t["card_subscriptions"]}
    picks = [x for x in sorted(t["card_invoice_lines"], key=lambda x: x["line_id"])
             if x["line_type"] == "recurring" and SEP1 <= x["invoice_date"] <= LAST and x["amount"] > 0
             and x["subscription_id"] in subs and subs[x["subscription_id"]]["ended_on"] is None][:3]
    _need(len(picks), "no line qualifies")
    existing = {x["line_id"] for x in t["card_invoice_lines"]}
    added = []
    for x in picks:
        n = 1
        while f"H09-{x['line_id']}-{n}" in existing:
            n += 1
        new = dict(x, line_id=f"H09-{x['line_id']}-{n}")
        existing.add(new["line_id"])
        t["card_invoice_lines"].append(new)
        added.append(new["line_id"])
    return {"lines_duplicated": [x["line_id"] for x in picks], "added": added}


def h10_late_usage_relabelled(b: dict) -> dict:
    """H10 (systems disagree): late August usage relabelled as loaded before the cutoff."""
    t = b["tables"]
    plans = _by(t["product_plan_changes"], "workspace_id")
    late = {(x["workspace_id"], "self_serve") for x in t["card_invoice_lines"]
            if x["line_type"] == "usage_late" and x["invoice_date"] == OCT5 and x["period_start"] == AUG1}
    late |= {(x["workspace_id"], "contract") for x in t["contract_invoice_lines"]
             if x["line_type"] == "usage_late" and x["invoice_date"] == OCT5 and x["period_start"] == AUG1}
    lo, hi = dt.datetime(2026, 9, 5), dt.datetime(2026, 9, 6)
    kinds = {}
    picks = []
    for r in sorted(t["usage_daily"], key=lambda r: r["usage_id"]):
        if not (_month(r["usage_date"]) == AUG1 and r["runs"] > 0 and lo <= r["loaded_at"] < hi):
            continue
        w = r["workspace_id"]
        if w not in kinds:
            kinds[w] = _plan_throughout(plans.get(w, []), JUL1, LAST)
        if kinds[w] in ("self_serve", "contract") and (w, kinds[w]) in late:
            picks.append(r)
            if len(picks) == 10:
                break
    _need(len(picks), "no usage row qualifies")
    for r in picks:
        r["loaded_at"] = dt.datetime(2026, 9, 4, 23, 59, 59)
    return {"usage_rows": [r["usage_id"] for r in picks], "workspaces": sorted({r["workspace_id"] for r in picks})}


def h11_migration_link_erased(b: dict) -> dict:
    """H11 (systems disagree): workspace link erased during a September migration."""
    t = b["tables"]
    opps = {o["opportunity_id"]: o for o in t["crm_opportunities"]}
    contracts = _by(t["crm_contracts"], "account_id")
    customers = _by(t["card_customers"], "workspace_id")
    subs = _by(t["card_subscriptions"], "customer_id")
    plans = _by(t["product_plan_changes"], "workspace_id")
    pick = None
    for a in sorted(t["crm_accounts"], key=lambda a: a["account_id"]):
        if not a["workspace_id"]:
            continue
        w = a["workspace_id"]
        for c in sorted(contracts.get(a["account_id"], []), key=lambda c: c["contract_id"]):
            o = opps.get(c["opportunity_id"])
            if not (_month(c["service_start"]) == SEP1 and c["service_end"] >= LAST and o is not None
                    and o["opportunity_type"] == "migration" and o["stage"] == "closed_won"):
                continue
            ended = any(s["ended_on"] == c["service_start"] - dt.timedelta(days=1)
                        for cu in customers.get(w, []) for s in subs.get(cu["customer_id"], []))
            switched = any(p["effective_date"] == c["service_start"] and p["plan_kind"] == "contract" for p in plans.get(w, []))
            if ended and switched:
                pick = (a, c)
                break
        if pick:
            break
    _need(pick is not None, "no account qualifies")
    a, c = pick
    w = a["workspace_id"]
    a["workspace_id"] = None
    return {"account": a["account_id"], "workspace": w, "contract": c["contract_id"]}


def h12_contract_charge_missing(b: dict) -> dict:
    """H12 (systems disagree): paid September contract charge missing from the invoice extract."""
    t = b["tables"]
    contracts = {c["contract_id"]: c for c in t["crm_contracts"]}
    pays = _by(t["contract_payments"], "invoice_id")
    totals = _invoice_totals(t["contract_invoice_lines"])
    pick = None
    for x in sorted(t["contract_invoice_lines"], key=lambda x: x["line_id"]):
        c = contracts.get(x["contract_id"])
        if not (x["line_type"] == "recurring" and SEP1 <= x["invoice_date"] <= LAST and x["amount"] > 0 and c is not None
                and c["service_start"] <= LAST <= c["service_end"]):
            continue
        ps = pays.get(x["invoice_id"], [])
        if len(ps) == 1 and ps[0]["paid_on"] <= OCT5 and ps[0]["amount"] == totals[x["invoice_id"]]:
            pick = x
            break
    _need(pick is not None, "no line qualifies")
    t["contract_invoice_lines"].remove(pick)
    return {"line_deleted": pick["line_id"], "invoice": pick["invoice_id"], "contract": pick["contract_id"],
            "amount": float(pick["amount"])}


FAULTS = [
    ("H01", h01_bus_m_price_wrong), ("H02", h02_coupons_dropped), ("H03", h03_discount_five_points_low),
    ("H04", h04_ramp_year_two_copied), ("H05", h05_september_runs_doubled), ("H06", h06_current_ramp_tier_lost),
    ("H07", h07_seat_decrease_early), ("H08", h08_annual_optout_as_cancel), ("H09", h09_card_lines_duplicated),
    ("H10", h10_late_usage_relabelled), ("H11", h11_migration_link_erased), ("H12", h12_contract_charge_missing),
]
