<?php
require_once '/home/akgbilis/fi_sf/config.php';
require_once __DIR__ . '/../auth_middleware.php'; // JWT doğrulama için

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

try {
    $stmt = $pdo->query("SELECT * FROM matches ORDER BY date DESC, time DESC");
    $matches = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode([
        'success' => true,
        'matches' => $matches
    ]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => 'Veri alınamadı',
        'details' => $e->getMessage()
    ]);
}