<?php
session_start();
require 'config.php';
require 'alerts_service.php';

header('Content-Type: application/json; charset=UTF-8');

if (!isset($_SESSION['user_id'])) {
    http_response_code(401);
    echo json_encode(['status' => 'error', 'message' => 'غير مسموح']);
    exit;
}

$alertService = new AlertService($conn, $_SESSION['user_id']);
$count = $alertService->markAllAsRead();

if ($count !== false) {
    echo json_encode([
        'status' => 'success',
        'message' => "تم تحديد $count تنبيه كمقروء",
        'count' => $count
    ], JSON_UNESCAPED_UNICODE);
} else {
    http_response_code(500);
    echo json_encode([
        'status' => 'error',
        'message' => 'فشل تحديث التنبيهات'
    ], JSON_UNESCAPED_UNICODE);
}

