<?php
include_once(__DIR__."/api-common.php");
include_once(__DIR__."/../my-optician-wsdl-service/MyOpticianWsdlService.php");
global $service_url, $optician_id;

checkGet();
// errorIfNotSet('shop_name');
// errorIfNotSet('practitioner_name');
$shop_name = $_GET['shop_name'];
$practitioner_name = $_GET['practitioner_name'];

// Instantiate the MyOpticianWsdlService class
$opticianService = new MyOpticianWsdlService($service_url, $optician_id);
$siteId = null;
if(isset($_GET['site_id']))
    $siteId = $_GET['site_id'];
else{
    $siteInfo = $opticianService->getSiteInfo($optician_id, $password);
    $siteId = $siteInfo->getSite();
    $password = $siteInfo->getPassword();
}

// Call the getPractitioners method
$appointments = $opticianService->getAppointments($siteId, $password, 
    $shop_name, $practitioner_name);

// Output the result as JSON
header('Content-Type: application/json');
echo json_encode(['data'=>$appointments]);
?>