#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Verifikasi fresh dari API: jadwal LinkedIn TS Law 2-11 Sep (harus pending, replies kosong)."""
import sys
sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import ReplizClient, ACC

client = ReplizClient()
acc = ACC.TSLAW_LINKEDIN
OLD_IDS = {"6a96a4440f4e8a4dace80a4c","6a96a444f197bea385845eca","6a96a4440f4e8a4dace80a60",
           "6a96a4450f4e8a4dace80a68","6a96a445f197bea385845ee6","6a9768630f4e8a4dac045d7a",
           "6a976864f197bea38594eb2b","6a976864f197bea38594eb39","6a9768640f4e8a4dac045dd4",
           "6a976865f197bea38594eb45"}

rows, old_left = [], []
page = 1
while True:
    data = client.get_schedules(page=page, limit=100)
    docs = data.get("docs") or data.get("data") or []
    if not docs:
        break
    for s in docs:
        if s.get("accountId") != acc:
            continue
        at = s.get("scheduleAt", "")
        if at[:10] >= "2026-09-02" and at[:10] <= "2026-09-11":
            rows.append(s)
        if s.get("id") in OLD_IDS:
            old_left.append(s)
    total = data.get("totalDocs") or data.get("total") or 0
    if page * 100 >= total or len(docs) < 100:
        break
    page += 1

rows.sort(key=lambda x: x.get("scheduleAt"))
print(f"Jadwal LinkedIn TS Law 2-11 Sep (fresh): {len(rows)}")
bad = 0
for s in rows:
    nrep = len(s.get("replies") or [])
    flag = "OK" if (s.get("status") == "pending" and nrep == 0) else "!!"
    if flag == "!!":
        bad += 1
    print(f"  [{flag}] {s.get('scheduleAt')} | {s.get('status'):7s} | replies={nrep} | {s.get('id')}")
print(f"\nSisa schedule ID lama yg masih ada di API: {len(old_left)}")
for s in old_left:
    print(f"  LEFTOVER {s.get('id')} | {s.get('scheduleAt')} | {s.get('status')}")
print(f"\nVerifikasi: {'✅ SEMUA BERSIH' if bad == 0 and len(old_left) == 0 and len(rows) == 10 else '⚠️ ADA MASALAH'}")
