#!/usr/bin/env python3
"""Diagnosa pipeline DAS short-daily: cek jadwal yang benar-benar ada di Repliz."""
import json

DUMP = "/tmp/repliz_all_sched.json"
ACC = {
    "DAS THREADS": "6a39e461c5ff4ce3a3233e09",
    "DAS FB": "6a3b41e1c5ff4ce3a327543e",
}

d = json.load(open(DUMP))
for label, acc in ACC.items():
    rows = [s for s in d if s.get("accountId") == acc]
    pending = [s for s in rows if s.get("status") in ("pending", "draft", "error")]
    print(f"=== {label}: {len(rows)} jadwal total")
    print(f"    pending/draft/error depan:")
    for s in sorted(pending, key=lambda x: x.get("scheduleAt") or "")[:14]:
        desc = (s.get("description") or "").replace("\n", " ")[:64]
        print(f"      {s.get('scheduleAt')} [{s.get('status')}] {s.get('type')} | {desc}")
    succ = sorted([s.get("scheduleAt") or "" for s in rows if s.get("status") == "success"])
    print(f"    sukses: {len(succ)} | 3 terakhir: {succ[-3:]}")
