"""Dummy data for the ramp plan: 300 candidate merchants for a delivery program, the rate card, the recommended
settings and the preset scenarios. The ramp model itself runs in the page. 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"]
BANDS = {"Small": (3.10, 3.40), "Medium": (5.20, 5.60), "Large": (8.40, 9.30)}  # base fee, average freight cost per order


def main():
    merchants = []
    for n in range(1, 301):
        category = R.choice(CATEGORIES)
        band = R.choices(list(BANDS), [0.5, 0.35, 0.15])[0]
        aov = round(max(9, R.lognormvariate(3.45, 0.55)), 2)          # average order value
        orders = round(R.lognormvariate(5.2, 1.0))                      # orders a month
        freight = round(BANDS[band][1] * R.uniform(0.85, 1.2), 2)       # freight cost per order
        merchants.append({"id": n, "name": f"Merchant {n:03d}", "category": category, "band": band, "aov": aov,
                          "orders": orders, "gmv": round(orders * aov), "freight": freight})
    candidates = sum(m["gmv"] for m in merchants)
    out = {
        "months": [f"Month {i}" for i in range(1, 10)],
        "marketplaceGmv": round(candidates / 0.8),   # the candidates hold 80% of the marketplace's monthly sales
        "bands": [{"band": b, "fee": f, "freight": c} for b, (f, c) in BANDS.items()],
        "opsCost": 0.85,          # handling cost per order on top of freight
        "onboardCost": 180,       # one-time cost to bring a merchant on
        "ramp": [0.5, 1.0],       # share of a merchant's orders in its first month, then after
        "recommended": {"fee": 1.0, "budget": 30000, "coordinators": 2, "perCoordinator": 9, "gate": True,
                        "gateAov": 25, "target": 0.4, "targetMonth": 7},
        "scenarios": [
            {"name": "Recommended", "set": {}},
            {"name": "Fast ramp", "set": {"budget": 42000, "coordinators": 3}},
            {"name": "Low cost", "set": {"budget": 22000}},
            {"name": "No gate", "set": {"gate": False}},
            {"name": "Higher fees", "set": {"fee": 1.2}},
        ],
        "merchants": merchants,
    }
    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()
