#!/usr/bin/env python3
"""Scheduled platform update briefing for Herman — documents all recent platform work."""
from __future__ import annotations

import json
import sys
import urllib.request
from datetime import datetime, timezone

PLATFORM_UPDATE = """
Platform update Foodlinkk Command Center:

1. Projecten — unified opslag voor foto's, packaging, agent-output met klantkoppeling
2. Herman dashboard — widgets slepen, 5 viz-modi, agent goedkeuringen op dashboard
3. IT Ops — Dell R340 topologie, SysOps dagelijkse backup + update-scan via approval
4. Agent assets — marketing publish, research briefs, approvals → auto project koppeling
5. Viz engine — Marketing, Agents, IT Ops pagina's met 5 visualisatiestijlen
6. SysOps workflow — vraagt nu eerst goedkeuring voor update-scan vóór uitvoering
7. Herman briefing — documenteert dagelijks alle agent-acties in activiteitenlog
"""


def main() -> int:
    now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
    print(f"=== Herman platform update briefing {now} ===")

    try:
        req = urllib.request.Request(
            "http://127.0.0.1:8600/api/herman/briefing",
            data=b"{}",
            headers={"Content-Type": "application/json"},
            method="POST",
        )
        with urllib.request.urlopen(req, timeout=180) as resp:
            briefing = json.loads(resp.read().decode("utf-8"))
        print("Briefing OK — generated_at:", (briefing.get("generated_at") or "")[:19])
    except Exception as exc:
        print("Briefing generation failed:", exc, file=sys.stderr)
        return 1

    print(PLATFORM_UPDATE)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
