<?php
declare(strict_types=1);
session_start();
require_once '../../config.php';
require_once '../helpers.php';
header('Content-Type: application/json');
if (!isset($_SESSION['parent_id'])) { http_response_code(401); echo json_encode(['success'=>false]); exit; }
portalCsrfVerify();
$conn = getDBConnection();
if (!$conn instanceof mysqli) { echo json_encode(['success'=>false]); exit; }
$parentId = (int) $_SESSION['parent_id'];
if ((int) ($_POST['mark_all'] ?? 0) === 1) {
    $stmt = $conn->prepare("UPDATE parent_notifications SET is_read = 1 WHERE parent_id = ?");
    $stmt->bind_param('i', $parentId);
} else {
    $notificationId = (int) ($_POST['notification_id'] ?? 0);
    $stmt = $conn->prepare("UPDATE parent_notifications SET is_read = 1 WHERE id = ? AND parent_id = ?");
    $stmt->bind_param('ii', $notificationId, $parentId);
}
$stmt->execute();
$stmt->close();
echo json_encode(['success'=>true]);
