#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Dump detail lengkap beberapa jadwal Repliz berdasarkan id."""
import json
import sys
import urllib.request

sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import HEADERS, BASE  # noqa: E402

for sid in sys.argv[1:]:
    req = urllib.request.Request(f"{BASE}/public/schedule/{sid}", headers=HEADERS)
    try:
        with urllib.request.urlopen(req, timeout=60) as r:
            d = json.load(r)
    except Exception as e:
        body = getattr(e, "read", lambda: b"")()
        print(f"{sid}: ERROR {e} {body[:200]}")
        continue
    docs = d.get("docs", d.get("data", d))
    if isinstance(docs, list):
        docs = docs[0] if docs else {}
    print(f"--- {sid} ---")
    for k in ("_id", "id", "accountId", "type", "status", "state", "topic", "scheduleAt", "title"):
        print(f"  {k}: {docs.get(k)}")
    med = docs.get("medias") or []
    print(f"  medias: {[m.get('url','')[-60:] for m in med] if med else []}")
    print(f"  description ({len(docs.get('description') or '')} char):")
    print("   " + (docs.get("description") or "").replace("\n", "\n   "))
