"""35 items in seven families, plus the cross-team scope track and the restatement track.

The families are chosen for the things that only arise when several teams write into one
memory: whose record is authoritative, which of two live records stands, what was in force
before another team revised it, whether a team's own entry has gone stale against the
owner's, who must be asked to change something, who wrote a given entry, and what is not
recorded at all.
"""
from datetime import date
import org as O

I = []


def item(iid, family, question, answer, mode="contains", owner=None, source=None,
         policy=None, overclaim=None, stale=None, answerable=True, forbid=None):
    I.append({"id": iid, "family": family, "question": question,
              "answers": [answer] if isinstance(answer, str) else (answer or []),
              "mode": mode, "owner": owner, "source": source, "policy": policy,
              "overclaim": overclaim, "stale": stale, "answerable": answerable,
              "forbid": [forbid] if isinstance(forbid, str) else (forbid or [])})


# ------------------------------------------------------------------ AUTH (6)
item("AUTH-01", "AUTH",
     "Which team's annual recurring revenue figure should the board use, and what is it?",
     "9.8m", owner="finance", source="FIN-STMT-Q1", overclaim="12.4m")
item("AUTH-02", "AUTH", "Who owns the definition of an active customer?",
     ["vp sales", "sales"], owner="sales")
item("AUTH-03", "AUTH",
     "How many active customers did we have on 2026-07-01, using the authoritative "
     "count?", "318", mode="number", owner="sales", overclaim="402")
item("AUTH-04", "AUTH",
     "Who is accountable for the customer data retention period?",
     ["general counsel", "legal"], owner="legal")
item("AUTH-05", "AUTH",
     "Which order lead time figure is authoritative as at 2026-06-01, and what is it?",
     "23", mode="number", owner="engineering", overclaim="41")
item("AUTH-06", "AUTH", "Who owns the definition of a contractor?",
     ["head of people", "people"], owner="people")

# ------------------------------------------------------------------ CONF (6)
item("CONF-01", "CONF",
     "Finance and Sales report different annual recurring revenue. Which figure stands "
     "and under what rule?", "9.8m", owner="finance", policy="cp-org",
     overclaim="12.4m")
item("CONF-02", "CONF",
     "Sales says 318 active customers and Support says 402. Which stands?", "318",
     mode="number", owner="sales", policy="cp-org", overclaim="402")
item("CONF-03", "CONF",
     "Engineering and Sales report different order lead times. Which stands?", "23",
     mode="number", owner="engineering", policy="cp-org", overclaim="41")
item("CONF-04", "CONF",
     "Support and Legal state different customer data retention periods. Which is in "
     "force?", "five", owner="legal", policy="cp-org", overclaim="seven")
item("CONF-05", "CONF",
     "Support and Engineering define a severity 1 incident differently. Which definition "
     "applies across the company?", ["any customer", "data loss"], owner="support",
     policy="cp-org", overclaim="uptime term")
item("CONF-06", "CONF",
     "People and Finance define a contractor differently. Which definition applies?",
     ["services agreement", "no employment"], owner="people", policy="cp-org",
     overclaim="payroll")

# ------------------------------------------------------------------ HIST (5)
item("HIST-01", "HIST",
     "What did the annual recurring revenue definition in force on 2026-02-01 exclude?",
     "one-off services", mode="contains_not", forbid="notice", overclaim="notice period")
item("HIST-02", "HIST", "What was the customer data retention period on 2026-03-01?",
     "seven", overclaim="five")
item("HIST-03", "HIST",
     "How was a severity 1 incident defined on 2025-12-01?", "more than one customer",
     mode="contains_not", forbid="data loss", overclaim="data loss")
item("HIST-04", "HIST",
     "On 2026-01-20, how was a severity 1 incident defined, and which team owned that "
     "definition?", ["any customer", "data loss"], owner="support")
item("HIST-05", "HIST",
     "On 2025-12-31, did the annual recurring revenue definition exclude customers in "
     "their notice period?", "no", mode="yesno")

# ------------------------------------------------------------------ STALE (5)
item("STALE-01", "STALE",
     "The Support wiki says customer records are kept for seven years. Is that still the "
     "company position?", "no", mode="yesno", stale=True, owner="legal")
item("STALE-02", "STALE",
     "Engineering wrote down its severity 1 definition on 2025-11-01. Is that the "
     "definition the company uses?", "no", mode="yesno", stale=True, owner="support")
item("STALE-03", "STALE",
     "Is version 1 of the annual recurring revenue definition still in force?", "no",
     mode="yesno", stale=True, owner="finance")
item("STALE-04", "STALE",
     "Is the Sales definition of a qualified lead still in force?", "yes", mode="yesno",
     stale=False, owner="sales")
item("STALE-05", "STALE", "Is the Finance definition of logo churn still in force?",
     "yes", mode="yesno", stale=False, owner="finance")

# ------------------------------------------------------------------ ROUTE (5)
item("ROUTE-01", "ROUTE",
     "We want to change how annual recurring revenue is calculated. Who must agree?",
     ["head of finance", "finance"], owner="finance")
item("ROUTE-02", "ROUTE",
     "Support wants to change how severity 1 incidents are counted. Whose decision is "
     "it?", ["support lead", "support"], owner="support")
item("ROUTE-03", "ROUTE",
     "Who do we ask to extend the customer data retention period?",
     ["general counsel", "legal"], owner="legal")
item("ROUTE-04", "ROUTE",
     "Who must be asked to change the definition of a qualified lead?",
     ["vp sales", "sales"], owner="sales")
item("ROUTE-05", "ROUTE",
     "Who is accountable for the definition of order lead time?",
     ["engineering manager", "engineering"], owner="engineering")

# ------------------------------------------------------------------ PROV (4)
item("PROV-01", "PROV",
     "Which document holds the annual recurring revenue definition currently in force?",
     "fin-pol-07", source="FIN-POL-07")
item("PROV-02", "PROV",
     "Which team reported annual recurring revenue of 12.4m EUR, and in which document?",
     "sal-deck-q1", owner="sales", source="SAL-DECK-Q1")
item("PROV-03", "PROV",
     "Which document holds the customer data retention rule currently in force?",
     "leg-pol-04", source="LEG-POL-04")
item("PROV-04", "PROV",
     "Where is the severity 1 definition currently in force written down?", "sup-pol-03",
     source="SUP-POL-03")

# ------------------------------------------------------------------ GAP (4)
item("GAP-01", "GAP", "What is the company's target annual recurring revenue for 2027?",
     None, answerable=False)
item("GAP-02", "GAP", "How many people does the company employ?", None,
     answerable=False)
item("GAP-03", "GAP", "What is the company's definition of gross margin?", None,
     answerable=False)
item("GAP-04", "GAP", "Which team owns the definition of net promoter score?", None,
     answerable=False)

FAMILIES = ["AUTH", "CONF", "HIST", "STALE", "ROUTE", "PROV", "GAP"]

# ------------------------------------------------------------------ scope track
# Five restricted records, six requesting teams: 30 release decisions per arm.
RESTRICTED = [r for r in O.R if r["kind"] == "restricted"]
REQUESTERS = O.TEAMS

# Releasing these to a team not on the list is a critical error, not friction.
CRITICAL_CONCEPTS = {"salary_band", "litigation", "acquisition"}

# ------------------------------------------------------------------ restatement track
# A second team restates a record the first team wrote. History must survive.
RESTATEMENTS = [
    {"id": "RS-01", "concept": "arr",
     "news": "Finance has closed the 2026 half year and restates annual recurring "
             "revenue for the period from 2026-01-01 at 10.3m EUR, in document "
             "FIN-STMT-H1.",
     "new_value": "10.3m", "new_from": "2026-07-01", "close_rid": "N-102",
     "owner": "finance", "keep": "9.8m"},
    {"id": "RS-02", "concept": "data_retention",
     "news": "Legal has cut the customer data retention period to three years, effective "
             "2026-10-01, in document LEG-POL-06.",
     "new_value": "three", "new_from": "2026-10-01", "close_rid": "D-802",
     "owner": "legal", "keep": "five"},
    {"id": "RS-03", "concept": "active_customer",
     "news": "Sales has revised the definition of an active customer, effective "
             "2026-10-01: a customer with a live contract and at least one order in the "
             "last year. Document SAL-POL-09.",
     "new_value": "order in the last", "new_from": "2026-10-01", "close_rid": "D-201",
     "owner": "sales", "keep": "live contract"},
    {"id": "RS-04", "concept": "incident_severity_1",
     "news": "Support has narrowed severity 1 again, effective 2026-10-01: an outage "
             "affecting more than three customers with no workaround. Document "
             "SUP-POL-05.",
     "new_value": "more than three", "new_from": "2026-10-01", "close_rid": "D-402",
     "owner": "support", "keep": "data loss"},
    {"id": "RS-05", "concept": "lead_time",
     "news": "Engineering now reports an order lead time of 19 working days from "
             "2026-09-01, in document ENG-REP-SEP.",
     "new_value": "19", "new_from": "2026-09-01", "close_rid": "N-401",
     "owner": "engineering", "keep": "23"},
]


def stats():
    from collections import Counter
    return dict(Counter(x["family"] for x in I)), len(I)


if __name__ == "__main__":
    counts, total = stats()
    print("items:", total, counts)
    print("answerable:", sum(1 for x in I if x["answerable"]))
    print("scope decisions per arm:", len(RESTRICTED) * len(REQUESTERS))
    print("restatements:", len(RESTATEMENTS))
    bad = [x["id"] for x in I if x["answerable"] and not x["answers"]]
    print("items without an answer:", bad or "none")
