<?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/poi.php';

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

// prepare product object
$Poi = new Poi($db);

// set Id property of record to read

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

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

// products array
$pois_arr = array();
$pois_arr["records"] = array();

if ($Poi->Name != null) {
    // create array
    $poi_item = array(
        "Id" => $Poi->Id,
        "destinationId" => $Poi->destinationId,
        "typeId" => $Poi->typeId,
        "Name" => $Poi->Name,
        "Description" => $Poi->Description,
        "Street" => $Poi->Street,
        "StreetNumber" => $Poi->StreetNumber,
        "Postcode" => $Poi->Postcode,
        "Latitude" => $Poi->Latitude,
        "Longtitude" => $Poi->Longtitude,
        "imageURL" => $Poi->imageURL,
        "Recommended" => $Poi->Recommended
    );
    array_push($pois_arr["records"], $poi_item);
    // set response code - 200 OK
    http_response_code(200);

    // make it json format
    echo json_encode($pois_arr);
} else {
    // set response code - 404 Not found
    http_response_code(404);

    // tell the user product does not exist
    echo json_encode(array("message" => "POI does not exist."));
}
?>