#!/usr/bin/env python3
import hashlib, uuid, subprocess, os, sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

status = "ACTIVE"
for arg in sys.argv:
    if arg.startswith("--status="):
        status = arg.split("=")[1]

FLAG_FILE = os.path.expanduser("~/.config/acreetion-ping-notified")

def show_privacy_dialog():
    window = Gtk.Window(title="AcreetionOS Privacy Notice")
    window.set_border_width(20)
    window.set_position(Gtk.WindowPosition.CENTER)
    vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
    window.add(vbox)
    label = Gtk.Label()
    label.set_markup("<span size='large' weight='bold'>Infrastructure Health Monitor</span>\n\n"
                     "Anonymous health ping enabled for 99.9% uptime.\n"
                     "<b>Privacy:</b> Your ID is scrambled locally via SHA-256.")
    label.set_line_wrap(True)
    vbox.pack_start(label, True, True, 0)
    btn = Gtk.Button(label="I Understand")
    btn.connect("clicked", Gtk.main_quit)
    vbox.pack_start(btn, True, True, 0)
    window.show_all()
    Gtk.main()

uid = hashlib.sha256((str(uuid.getnode()) + "AcreetionOS_2026").encode()).hexdigest()[:12]
if not os.path.exists(FLAG_FILE):
    show_privacy_dialog()
    os.makedirs(os.path.dirname(FLAG_FILE), exist_ok=True)
    with open(FLAG_FILE, "w") as f: f.write("notified")

subprocess.run(f"curl -k -s -d 'uid={uid}&status={status}' http://iso.acreetionos.org:8449/api/report", shell=True)
