<?php
//////////////////////////////////////
header("Access-Control-Allow-Origin: *");
include_once('OAuth.php');
//////////// SAAS ENV ////////////////////////////////////////////////////
require_once("class.restframework.php");
require_once("class.saas.php");
include_once('class.booking.php');
////////////////////////////////////////////////////////////////////////
$restapi = new RestFrameWork();
// alow get ######## 
$restapi->allow("get");
// only allow get method
$saas = new SaaS($restapi);
$auth = $saas->_initAuth();
////////////////////////////////////////////////////////////////////////
$booking = new Booking($auth, $restapi);
///////////////////////////////////////////////////////////////////////
if ($restapi->purge("booking_id")) {
    $booking_id = $_GET["booking_id"];
    $response = $booking->getBookingById($booking_id);
    if ($response["success"]) {
        echo $restapi->Response($response);
    } else {
        echo $restapi->Response($response, 400);
    }
} else {
    $id_user = isset($_GET["id_user"]) && !empty($_GET["id_user"]) ? $_GET["id_user"] : null;
    $status = isset($_GET["status"]) && !empty($_GET["status"]) ? $_GET["status"] : null;
    $response = $booking->getAllBookings($id_user, $status);
    echo $restapi->Response($response);
}
