<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    exit(0);
}

require_once 'config.php';

try {
    $siteID = $_GET['SiteID'] ?? '';

    if (empty($siteID)) {
        echo json_encode(["success" => false, "message" => "SiteID manquant"]);
        exit();
    }

    // Récupérer les tarifications
    $stmt = $pdo->prepare("SELECT designation, designationAR, prix FROM Tarifications_Parking WHERE SiteID = ? AND (date_validite IS NULL OR date_validite >= CURDATE()) ORDER BY prix ASC");
    $stmt->execute([$siteID]);
    $tarifications = $stmt->fetchAll(PDO::FETCH_ASSOC);

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

} catch (Exception $e) {
    error_log("Erreur get_tarifications: " . $e->getMessage());
    echo json_encode([
        "success" => false,
        "message" => "Erreur serveur: " . $e->getMessage()
    ]);
}

?>
