/**
 * Push notif eksternal untuk admin saat ada cron FAILED atau alert critical.
 * Saat ini support Discord webhook (paling simple). Fail silent — kalau env
 * tidak di-set, no-op. Kalau request gagal, console.error tapi tidak throw.
 *
 * Env `ADMIN_ALERT_WEBHOOK_URL` — Discord channel webhook URL.
 */

export async function notifyAdmins(message: string): Promise<void> {
  const webhookUrl = process.env.ADMIN_ALERT_WEBHOOK_URL;
  if (!webhookUrl) return;

  try {
    await fetch(webhookUrl, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        // Format Discord webhook: `content` adalah body message plaintext/markdown.
        content: `🚨 **SeTrip Admin Alert**\n${message}`,
      }),
    });
  } catch (err) {
    console.error("[admin-notify] gagal kirim ke webhook", err);
  }
}
