<?php
session_start();
header('Content-Type: application/json');
if (empty($_SESSION['csr_id'])) { echo json_encode(['success'=>false,'message'=>'Unauthorized']); exit; }
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../includes/announcement_system.php';
try {
    $db = (new Database())->getConnection();
    $data = annGetUnreadForUser($db, (int)$_SESSION['csr_id'], isset($_GET['limit']) ? (int)$_GET['limit'] : 8);
    echo json_encode(['success'=>true] + $data);
} catch (Throwable $e) {
    error_log('unified get_unread_announcements failed: '.$e->getMessage());
    echo json_encode(['success'=>false,'message'=>'Announcement check failed.']);
}
