#!/usr/bin/env python3
"""Hapus jadwal storytelling uky LAMA (tanpa framework 5 babak) — ganti versi framework."""
import sys, json, urllib.request
sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import HEADERS, BASE

UKY_T = "6a334e89c5ff4ce3a3225a48"

# cari jadwal storytelling pending yang captionnya TIDAK mengandung struktur framework
old_ids = []
for p in range(1, 80):
    raw = urllib.request.Request(f"{BASE}/public/schedule?page={p}&limit=100", headers=HEADERS)
    with urllib.request.urlopen(raw, timeout=30) as r:
        docs = json.load(r)["docs"]
    for d in docs:
        if d.get("accountId") == UKY_T and (d.get("status") or "").lower() == "pending":
            desc = d.get("description") or ""
            topic = d.get("topic") or ""
            if topic == "Storytelling" or "#Storytelling" in desc:
                if "Konteks" not in desc and "• Konteks" not in desc:
                    old_ids.append((d.get("scheduleAt"), d["id"], (d.get("title") or "")[:50]))

print(f"jadwal storytelling LAMA (tanpa framework): {len(old_ids)}")
for at, sid, t in sorted(old_ids):
    print(f"  {at} | {sid} | {t}")

if len(sys.argv) > 1 and sys.argv[1] == "exec":
    print("\n=== DELETE ===")
    for at, sid, t in old_ids:
        req = urllib.request.Request(f"{BASE}/public/schedule/{sid}", headers=HEADERS, method="DELETE")
        with urllib.request.urlopen(req, timeout=30) as r:
            print(f"  ✅ DEL {sid} ({at})")
