<?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 {
    $annId = (int)($_POST['announcement_id'] ?? 0);
    if ($annId <= 0) throw new Exception('Missing announcement id.');
    $db = (new Database())->getConnection();
    annMarkRead($db, $annId, (int)$_SESSION['csr_id']);
    echo json_encode(['success'=>true,'message'=>'Marked as read.']);
} catch (Throwable $e) {
    error_log('unified mark_announcement_read failed: '.$e->getMessage());
    echo json_encode(['success'=>false,'message'=>$e->getMessage()]);
}
