<?php
/**
 * API: Liste des bus
 * GET /apipcc/bus_list.php
 */
require_once __DIR__ . '/config.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    sendError('Méthode non autorisée', 405);
}

$conn = getConnection(DB_NAME_PARCS);

$query = "SELECT Num_Parc, DateExp, Etat, DateEtat FROM bus ORDER BY Num_Parc";
$result = $conn->query($query);

$buses = [];
if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $buses[] = $row;
    }
}

sendSuccess($buses, 'Liste des bus récupérée');
$conn->close();