<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
 
// include database and object files
include_once '../config/database.php';
include_once '../objects/restaurant.php';
 
// get database connection
$database = new Database();
$db = $database->getConnection();
 
// prepare product object
$Restaurant = new Restaurant($db);
 
// set Id property of record to read

$Restaurant->Id = isset($_GET['Id']) ? $_GET['Id'] : die();

// read the details of product to be edited
$Restaurant->readOne();

    // products array
    $restaurants_arr=array();
    $restaurants_arr["records"]=array();
    
if($Restaurant->Name!=null){
    // create array
    $restaurant_item = array(
        "Id" =>  $Restaurant->Id, 
        "destinationId" =>  $Restaurant->destinationId, 
        "Name" => $Restaurant->Name,
        "Description" => $Restaurant->Description,
        "Street" => $Restaurant->Street,
        "StreetNumber" => $Restaurant->StreetNumber,
        "Postcode" => $Restaurant->Postcode,
        "Latitude" => $Restaurant->Latitude,
        "Longtitude" => $Restaurant->Longtitude,
        "imageURL" => $Restaurant->imageURL,
        "Recommended" => $Restaurant->Recommended
    );
    array_push($restaurants_arr["records"], $restaurant_item);
    // set response code - 200 OK
    http_response_code(200);
 
    // make it json format
    echo json_encode($restaurants_arr);
}
 
else{
    // set response code - 404 Not found
    http_response_code(404);
 
    // tell the user product does not exist
    echo json_encode(array("message" => "Restaurant does not exist."));
}
?>