"""Dummy data for the seller input prototype: 80 sellers with their pick-pack-prep times, on-time rates and monthly
sales, the review rules, and a queue of recent changes. 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 json
import os
import random

R = random.Random(20261102)
CATEGORIES = ["Home", "Fashion", "Electronics", "Beauty", "Sports"]
PREP = [12, 24, 36, 48, 72]


def band(orders):
    return "Large" if orders >= 800 else "Medium" if orders >= 250 else "Small"


def main():
    sellers = []
    for n in range(1, 81):
        category = R.choice(CATEGORIES)
        orders = round(R.lognormvariate(5.7, 0.8))
        prep = R.choices(PREP, [0.1, 0.4, 0.2, 0.2, 0.1])[0]
        on_time = max(0.6, min(0.98, 0.95 - 0.0028 * prep + R.gauss(0, 0.025)))   # slower prep, fewer on-time deliveries
        aov = R.uniform(28, 60)
        sellers.append({"id": n, "name": f"Seller {n:02d}", "category": category, "band": band(orders), "orders": orders,
                        "prep": prep, "onTime": round(on_time, 3), "gmv": round(orders * aov)})
    rules = {
        "trivial": 0.03,        # a faster prep time, or an on-time drop under 3 points, is accepted on its own
        "lostShare": 0.35,      # share of late orders that end in a cancellation or return
        "urgentGmv": 350,       # monthly sales at risk that sends a change straight to a person
        "minPeers": 4,          # below this, peers are the whole category
    }
    queue = []
    for _ in range(10):
        s = R.choice(sellers)
        new = R.choice([p for p in PREP if p != s["prep"]])
        queue.append({"seller": s["id"], "new": new, "when": f"{R.randint(1, 23)} h ago"})
    out = {"sellers": sellers, "rules": rules, "prepOptions": PREP, "queue": queue}
    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()
