<?php
require_once '../config.php';
require_once '../../includes/Auth.php';
require_once '../../includes/Notification.php';

$auth = new Auth();
$user = $auth->requireAuth();

$notification = new Notification();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $input = json_decode(file_get_contents('php://input'), true);
    $notification_ids = $input['ids'] ?? [];

    if (empty($notification_ids)) {
        jsonResponse(['success' => true, 'message' => 'No notifications to mark as read.']);
    }

    try {
        $notification->markAsRead($notification_ids, $user['id']);
        jsonResponse(['success' => true, 'message' => 'Notifications marked as read.']);
    } catch (Exception $e) {
        jsonResponse(['success' => false, 'message' => $e->getMessage()], 500);
    }
}
?>