#!/usr/bin/env python3
"""Generate data/big_orders.json (200k orders, single-line JSON array) and the
expected stream-total answer, computed with the POL-114-correct formula."""
import json
import random
import sys

random.seed(20260809)
N = 200_000
TAX = 0.0875

out_path, expected_path = sys.argv[1], sys.argv[2]
total = 0.0
with open(out_path, "w") as f:
    f.write("[")
    for i in range(N):
        n_items = random.randint(1, 4)
        items = [{"qty": random.randint(1, 9),
                  "unit_price": round(random.uniform(1, 300), 2)} for _ in range(n_items)]
        discount = round(random.uniform(0, 20), 2) if random.random() < 0.3 else 0.0
        o = {"order_id": f"B{i:06d}", "customer": f"C{random.randint(1, 5000)}",
             "line_items": items}
        if discount:
            o["discount"] = discount
        sub = sum(li["qty"] * li["unit_price"] for li in items)
        total += round(max(sub - discount, 0.0) * (1 + TAX), 2)  # POL-114 §3 clamp
        f.write(("," if i else "") + json.dumps(o, separators=(",", ":")))
    f.write("]")
open(expected_path, "w").write(f"{round(total, 2):.2f}\n")
print(f"wrote {N} orders, expected total {round(total, 2):.2f}")
