<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require_once '../includes/db.php';
require_once '../includes/auth.php';

check_role('alumno');

$user = get_logged_in_user();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['notification_id'])) {
        $notification_id = (int)$_POST['notification_id'];
        $stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE id = ? AND user_id = ?");
        $stmt->execute([$notification_id, $user['id']]);
    } elseif (isset($_POST['mark_all'])) {
        $stmt = $pdo->prepare("UPDATE notifications SET is_read = 1 WHERE user_id = ? AND is_read = 0");
        $stmt->execute([$user['id']]);
    }
}

header('Content-Type: application/json');
echo json_encode(['success' => true]);
?>