#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Verifikasi 4 jadwal Threads baru 5 Okt 2026 dari API (baca balik per id)."""
import sys, datetime, json, re
sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import ReplizClient

WIB = datetime.timezone(datetime.timedelta(hours=7))
IDS = {
    "uky": "6ac2bf3407008e0e91e93e62",
    "tslaw": "6ac2bf3407008e0e91e93e66",
    "tsc": "6ac2bf3507008e0e91e93e6c",
    "das": "6ac2bf3507008e0e91e93e74",
}
cli = ReplizClient()
URL_RE = re.compile(r"https?://\S+")
MENTION_RE = re.compile(r"@\w+")
CJK = re.compile(r"[\u3000-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff00-\uffef]")
CTA_RE = re.compile(r"komentar|diskusi|pendapat|tulis di|share|pengalaman|menurut anda|menurut kamu|setuju|ceritakan", re.I)

allok = True
for acc, sid in IDS.items():
    chk = cli.get_schedule(sid)
    s = chk.get("schedule") or chk
    dt = datetime.datetime.fromisoformat(s["scheduleAt"].replace("Z", "+00:00")).astimezone(WIB)
    desc = s.get("description") or ""
    tags = re.findall(r"#(\w+)", desc)
    reps = s.get("replies") or []
    med = s.get("medias") or []
    cek = {
        "status": s.get("status"),
        "jam": dt.strftime("%Y-%m-%d %H:%M"),
        "len": len(desc),
        "link": bool(URL_RE.search(desc)),
        "cta_ekor": bool(CTA_RE.search(desc[-170:])),
        "mention": bool(MENTION_RE.search(desc)),
        "cjk": bool(CJK.search(desc)),
        "tag_kecil": all(x == x.lower() for x in tags),
        "replies": len(reps),
        "media": len(med),
        "topic": s.get("topic"),
        "title": s.get("title"),
        "type": s.get("type"),
    }
    baik = (cek["status"] == "pending" and cek["jam"].startswith("2026-10-05")
            and cek["len"] <= 500 and cek["link"] and cek["cta_ekor"]
            and not cek["mention"] and not cek["cjk"] and cek["tag_kecil"]
            and cek["replies"] == 0 and cek["media"] == 0)
    allok &= baik
    print(f"\n{'✅' if baik else '⚠️'} {acc} id={sid}")
    print("   " + json.dumps(cek, ensure_ascii=False))
    print("   desc:", desc.replace("\n", " ⏎ ")[:200])

print("\nSEMUA BAIK:", allok)
