"""Ops push notifications — Spec 007 phase A (onboarding events)."""

from __future__ import annotations

import os

from app import ntfy_notify

OPS_NTFY_TOPIC = os.getenv("DESK_OPS_NTFY_TOPIC", "").strip()
PUSH_ONBOARD_EVENTS = frozenset({
    "session.started",
    "onboarding.started",
    "onboarding.failed",
    "integration.gap",
})


def notify_ops_event(event: str, *, domain: str | None = None, detail: str = "") -> bool:
    if event not in PUSH_ONBOARD_EVENTS:
        return False
    if not OPS_NTFY_TOPIC:
        return False
    dom = domain or "sem domínio"
    title = f"Ligbox Ops — {event}"
    body = detail or dom
    priority = "high" if event in ("onboarding.started", "onboarding.failed", "integration.gap") else "default"
    return ntfy_notify.push(OPS_NTFY_TOPIC, title, body, priority=priority)
