<?php
/**
 * API endpoint لجلب التنبيهات
 */
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']);
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 50;

$alerts = $alertService->getUnreadAlerts($limit);

echo json_encode([
    'status' => 'success',
    'alerts' => $alerts,
    'count' => count($alerts)
], JSON_UNESCAPED_UNICODE);

