<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');

$slug = isset($_GET['slug']) ? trim($_GET['slug']) : '';
$slug = preg_replace('/[^0-9]/', '', $slug); // On ne garde QUE les chiffres pour les ID sécurisés

if (empty($slug)) {
    echo json_encode(['error' => true, 'message' => 'ID de parc manquant ou invalide.']);
    exit;
}

// URL d'API globale stable utilisant l'ID numérique
$url = "https://queue-times.com/parks/" . $slug . "/queue_times.json";

$options = [
    "http" => [
        "method" => "GET",
        "header" => "User-Agent: ParcoTripApp/1.0 (XAMPP Environment)\r\n" .
                    "Accept: application/json\r\n",
        "timeout" => 15
    ]
];
$context = stream_context_create($options);
$response = @file_get_contents($url, false, $context);

if ($response === false) {
    echo json_encode(['error' => true, 'message' => 'Impossible de joindre le serveur de données externe.']);
    exit;
}

echo $response;