"""Dummy data for the engineering plan: one quarter of work items in five streams, the people who own them, the dates
that frame the quarter, and the tracker's milestone dates to reconcile against. Every name, figure and date is invented.

Usage: python3 generate.py (writes data.json next to this file; a fixed seed makes every run identical)
"""
import datetime
import json
import os
import random

R = random.Random(20261102)
Q_START, Q_END = datetime.date(2026, 10, 1), datetime.date(2026, 12, 31)
PEOPLE = [
    {"id": "be1", "name": "Back end lead", "side": "Back end", "days": 5},
    {"id": "be2", "name": "Back end engineer", "side": "Back end", "days": 5},
    {"id": "fe1", "name": "Front end engineer", "side": "Front end", "days": 5},
    {"id": "ds1", "name": "Product designer", "side": "Design", "days": 3},
    {"id": "pm1", "name": "Product manager", "side": "Product", "days": 2},
]
# stream, item, owner, start offset (days from Oct 1), length in days, milestone
ITEMS = [
    ("Merchant fees", "Fee rules and rate card", "pm1", 0, 12, False),
    ("Merchant fees", "Fee calculation service", "be1", 8, 24, False),
    ("Merchant fees", "Fee statement screens", "ds1", 10, 14, False),
    ("Merchant fees", "Fee statement front end", "fe1", 22, 16, False),
    ("Merchant fees", "Fee launch", "pm1", 40, 1, True),
    ("Merchant invoicing", "Invoice data model", "be2", 4, 14, False),
    ("Merchant invoicing", "Monthly invoice run", "be2", 20, 18, False),
    ("Merchant invoicing", "Invoices live", "pm1", 52, 1, True),
    ("Carrier payments", "Carrier rate import", "be1", 34, 12, False),
    ("Carrier payments", "Payment reconciliation", "be2", 40, 20, False),
    ("Carrier payments", "Reconciliation review screen", "fe1", 45, 12, False),
    ("Carrier payments", "First reconciled payment", "pm1", 66, 1, True),
    ("Tracking page", "Tracking page design", "ds1", 26, 10, False),
    ("Tracking page", "Tracking page build", "fe1", 60, 16, False),
    ("Tracking page", "Tracking page live", "pm1", 80, 1, True),
    ("Peak readiness", "Load test and alarms", "be1", 48, 9, False),
    ("Peak readiness", "Runbooks for peak", "pm1", 50, 6, False),
    ("Peak readiness", "Code freeze", "pm1", 57, 1, True),
]
SIDES = ["Back end", "Front end", "Design", "Product"]


def main():
    items = []
    for n, (stream, name, owner, start, length, milestone) in enumerate(ITEMS):
        s = Q_START + datetime.timedelta(days=start)
        e = s + datetime.timedelta(days=length - 1)
        side = next(p["side"] for p in PEOPLE if p["id"] == owner)
        item = {"id": n + 1, "stream": stream, "name": name, "owner": owner, "side": side,
                "start": s.isoformat(), "end": e.isoformat(), "milestone": milestone}
        if milestone:
            slip = 0 if name == "Code freeze" else R.choice([0, 0, 0, 2, 4, 7])   # a freeze date never moves
            item["tracker"] = (e + datetime.timedelta(days=slip)).isoformat()
        items.append(item)
    out = {
        "start": Q_START.isoformat(), "end": Q_END.isoformat(), "asOf": "2026-11-02", "sides": SIDES,
        "markers": [
            {"name": "Fee launch", "date": "2026-11-10", "kind": "launch"},
            {"name": "Black Friday", "date": "2026-11-27", "kind": "freeze"},
        ],
        "people": PEOPLE, "items": items,
        "notes": [
            ["Merchant invoicing", "Invoices cover fees from launch day on. Earlier orders are not billed."],
            ["Carrier payment", "Payments start once one month of carrier bills reconciles within tolerance."],
            ["Out of scope", "Refunds of fees, multi-currency billing and a merchant-facing fee simulator."],
        ],
    }
    with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "data.json"), "w") as f:
        json.dump(out, f, separators=(",", ":"))


if __name__ == "__main__":
    main()
