<?php
/**
 * WorksAlertsController — cross-project exception dashboard.
 *
 *   /WorksAlerts   — every alert across every works project, grouped by severity.
 *
 * Read-only surface. All logic lives in WorksAlerts.
 */
class WorksAlertsController extends Controller
{
    public function indexAction()
    {
        if (!class_exists('WorksAlerts')) require_once ROOT . '/app/models/WorksAlerts.php';
        $wa = new WorksAlerts();
        $alerts = $wa->allAlerts();

        // Group by severity for the view
        $bySev = ['HIGH' => [], 'MEDIUM' => [], 'LOW' => []];
        foreach ($alerts as $a) $bySev[$a['severity']][] = $a;

        $this->view->setLayout($this->roleLayout());
        $this->view->render('WorksAlerts/index', [
            'page_title' => 'Works alerts',
            'alerts'     => $alerts,
            'by_sev'     => $bySev,
            'counts'     => [
                'HIGH'   => count($bySev['HIGH']),
                'MEDIUM' => count($bySev['MEDIUM']),
                'LOW'    => count($bySev['LOW']),
                'total'  => count($alerts),
            ],
        ]);
    }
}
