"""Populate the Promo Calendar with realistic dummy promotions so the
dashboard, gantt, conflicts and heatmap have something to render.

Run from inside the promocalendar folder:
    python seed_dummy_data.py
"""
from __future__ import annotations

from datetime import datetime
from uuid import uuid4

import pandas as pd

from promo_data import save_promos, PROMO_COLS

iso = datetime.now().isocalendar()
cy, cw = int(iso[0]), int(iso[1])
now_str = datetime.now().strftime("%Y-%m-%d %H:%M")


def _row(name, source, ptype, outcome, status, sw, ew, skus, units,
            cat="", owner="", notes=""):
    return {
        "id": uuid4().hex[:8],
        "name": name, "source": source, "type": ptype, "outcome": outcome,
        "status": status,
        "start_year": cy, "start_week": sw,
        "end_year": cy, "end_week": ew,
        "skus": skus, "units": units,
        "category": cat, "owner": owner, "notes": notes,
        "created_at": now_str, "updated_at": now_str,
    }


# Dummy promos spread across past 4 weeks → next 9 weeks (≈ CW-4 .. CW+9).
# Includes intentional conflicts on POL09754 and POL09755 so the
# conflict detector lights up.
rows = [
    # ---- Past / done ----
    _row("Rok istek batch", "B2C — MP (retail)", "Rok istek",
         "📦 Rješavanje lagera", "✓ done",
         cw - 4, cw - 2,
         "POL12848, POL12849, POL12850, POL12851",
         280, cat="PROTEINI", owner="Selma",
         notes="Stock clearance — successful, sold out CW17"),

    _row("Spring Vitamin Push", "B2C — WEB", "Kampanja",
         "👥 Novi kupci", "📊 analyzed",
         cw - 5, cw - 3,
         "ATC06500, ATC06501, ATC06502",
         420, cat="SPORTSKA PREHRANA", owner="Lovro",
         notes="Webshop landing page conversion +18 %"),

    # ---- Active ----
    _row("Live Loyalty Reward", "B2C — WEB", "Loyalty",
         "🚀 Traffic driver", "🟢 live",
         cw - 1, cw + 1,
         "POL09754, POL09760, POL09762",
         190, cat="SPORTSKA PREHRANA", owner="Lovro"),

    # ---- Upcoming - approved ----
    _row("Summer Protein Sale", "B2C — MP (retail)", "Univerzalna",
         "👥 Novi kupci", "🔧 preparing",
         cw + 2, cw + 5,
         "POL09754, POL09755, POL09752, POL12749, POL12750, POL12751, POL12752, POL04466",
         1840, cat="PROTEINI", owner="Selma",
         notes="Big Q2 push, all whey variants"),

    _row("Flash Creatine", "B2C — WEB", "Kampanja",
         "🚀 Traffic driver", "✅ approved",
         cw + 3, cw + 4,
         "POL09754, POL09755, POL09760",
         620, cat="SPORTSKA PREHRANA", owner="Lovro",
         notes="2-week flash, web-only"),

    _row("FMCG Push Q2", "B2B — FMCG", "Wholesale",
         "💰 Veći RUC", "✅ approved",
         cw + 3, cw + 5,
         "POL09755, POL12749, POL12750, POL12751, POL12752, POL12848, POL12849, POL12850, POL12851, POL12852, POL04466, POL04467",
         960, cat="PROTEINI", owner="Patrik VP",
         notes="Konzum + Spar + Kaufland coverage"),

    _row("Fitness Summer", "B2B — FITNESS", "Web",
         "👥 Novi kupci", "💡 idea",
         cw + 6, cw + 8,
         "POL09760, POL09762, POL09763, ATC06500, ATC06501, ATC06502",
         480, cat="SPORTSKA PREHRANA", owner="Patrik VP"),

    _row("Loyalty Week", "B2C — WEB", "Loyalty",
         "🚀 Traffic driver", "💡 idea",
         cw + 6, cw + 6,
         "POL09754, POL09755, POL09760, POL09762, POL09763",
         340, cat="MIX", owner="Lovro"),

    _row("Partner Weekend DM", "B2C — MP (retail)", "Partner / Passport",
         "💰 Veći RUC", "🔧 preparing",
         cw + 4, cw + 4,
         "POL12750, POL12751, POL12848",
         210, cat="PROTEINI", owner="Selma",
         notes="DM partner deal, 1-week-only"),

    _row("Back to School", "B2C — MP (retail)", "Univerzalna",
         "🚀 Traffic driver", "💡 idea",
         cw + 8, cw + 9,
         "ATC06500, ATC06501",
         180, cat="SPORTSKA PREHRANA", owner="Selma"),

    _row("BIPA Beauty Push", "B2B — FMCG", "Wholesale",
         "👥 Novi kupci", "💡 idea",
         cw + 7, cw + 9,
         "POL09784, POL09785",
         260, cat="BIO I SUPERFOODS", owner="Patrik VP"),

    _row("Otvaranje Zagreb West", "B2C — MP (retail)", "Otvaranje",
         "🚀 Traffic driver", "✅ approved",
         cw + 2, cw + 2,
         "POL09754, POL09755, POL12749, POL12750, POL12848, POL12849",
         150, cat="PROTEINI", owner="Selma",
         notes="New store opening, 1-week launch promo"),
]

df = pd.DataFrame(rows, columns=PROMO_COLS)
save_promos(df)
print(f"Seeded {len(rows)} dummy promotions covering CW{cw - 5} -> CW{cw + 9}.")
print()
print("Conflicts you'll see:")
print("  POL09754 — overlapping in 'Summer Protein Sale' (B2C MP) and 'Flash Creatine' (B2C WEB)")
print("  POL09755 — overlapping in 'Summer Protein Sale' (B2C MP) and 'FMCG Push Q2' (B2B FMCG)")
print("  POL12750 — overlapping in 'Summer Protein Sale' (B2C MP) and 'Partner Weekend DM' / 'FMCG Push Q2'")
print()
print("Refresh the Promo Calendar page in your browser.")
