<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include_once '../config/database.php';
include_once '../objects/vehicle.php';
include_once '../helpers/rental_metadata.php';

$database = new Database();
$db = $database->getConnection();

$vehicle = new Vehicle($db);
$data = json_decode(file_get_contents("php://input"));

if (isset($data->id)) {
    $vehicle->id = $data->id;
    $vehicle->getOneRow();

    $vehicle_meta = parse_vehicle_metadata($vehicle->remark);
    echo json_encode(array(
        "id" => $vehicle->id,
        "license_plate" => $vehicle->license_plate,
        "vehicle_category" => $vehicle->vehicle_category,
        "transmission" => $vehicle->transmission,
        "seats" => $vehicle->seats,
        "remark" => $vehicle_meta['note'],
        "vehicle_meta" => $vehicle_meta,
    ));
} else {
    echo json_encode(array("message" => "Vehicle ID is missing."));
}
?>
