<?php
/**
 * announcement-ajax.php — async JSON endpoint for Announcements mutations.
 * Thin wrapper around whp_ajax_endpoint (auth + CSRF + JSON envelope) + the
 * shared action handler. Announcements are root-only, so we add a root gate on
 * top of the standard auth gate. Mirrors api/database-ajax.php.
 */
require_once __DIR__ . '/../includes/whp-ajax-endpoint.php';   // also loads auto-prepend (AUTH_USER, CSRF)
require_once __DIR__ . '/../libs/announcement_manager.php';
require_once __DIR__ . '/../libs/announcement_actions.php';

whp_ajax_endpoint(function () {
    if (AUTH_USER !== 'root') {
        return ['message' => 'Only root users can manage announcements', 'type' => 'danger'];
    }
    $AnnouncementMgr = new announcement_manager();
    return whp_announcement_handle_action($AnnouncementMgr);
});
