import sys, json, urllib.request, urllib.parse
sys.path.insert(0,'.')
from repliz_client import HEADERS, BASE
IDS={'Threads':'6aad03359aa606c3bdb25c3f','IG':'6aad03369aa606c3bdb25c43','FB':'6aad03369aa606c3bdb25c4b'}
FN='tslaw_video_materai_0918_h264.mp4'
docs,page=[],1
while True:
    q=urllib.parse.urlencode({'page':page,'limit':100})
    req=urllib.request.Request(f'{BASE}/public/schedule?{q}',headers=HEADERS)
    with urllib.request.urlopen(req,timeout=60) as r: d=json.load(r)
    docs+=d.get('docs',d.get('data',[]))
    if not d.get('hasNextPage') or not docs: break
    page+=1
idx={str(s.get('_id') or s.get('id')):s for s in docs}
print('total jadwal terbaca:', len(docs))
allok=True
for label,sid in IDS.items():
    s=idx.get(sid)
    if not s:
        print(f'❌ {label}: id {sid} TIDAK DITEMUKAN'); allok=False; continue
    media=[m.get('url','') for m in (s.get('medias') or [])]
    okm = any(FN in u for u in media)
    rep = s.get('replies')
    st = s.get('state') or s.get('status')
    print(f"{label}: {st} | {s.get('type')} | {str(s.get('scheduleAt'))[:16]}Z | replies={rep} | media_ok={okm}")
    print(f"   url: {media}")
    print(f"   caption {len(s.get('description') or '')} char | title: {s.get('title')}")
    if not (st=='pending' and s.get('type')=='video' and okm and (rep in ([],None))): allok=False
print('\nHASIL:', 'SEMUA OK ✅' if allok else 'ADA MASALAH ❌')
