<?php
require_once __DIR__ . '/../auth_middleware.php';
require_once '/home/akgbilis/fi_sf/config.php';

header('Content-Type: application/json');

$user_id = $decoded->sub;

$stmt = $pdo->prepare("
    SELECT id, title, message, created_at, match_info, user_guess, match_result, read_at
    FROM notifications
    WHERE user_id = ?
    ORDER BY created_at DESC
");
$stmt->execute([$user_id]);
$rows = $stmt->fetchAll();

$notifications = [];

foreach ($rows as $row) {
    $notifications[] = [
        "id" => $row['id'],
        "title" => $row['title'],
        "message" => $row['message'],
        "created_at" => $row['created_at'],
        "match_info" => $row['match_info'],
        "user_guess" => $row['user_guess'],
        "match_result" => $row['match_result'],
        "read_at" => $row['read_at'] // ✅ Swift için doğrudan null veya tarih
    ];
}

echo json_encode([
    "success" => true,
    "notifications" => $notifications
]);