<?php
/*
    Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace GnuBoat;

require_once(__DIR__ ."/../autoloader.php");

class WebService
{
	function __construct($debug)
	{
		$this->_requests = array();
		$this->_requests["data"] = "GnuBoat\ServiceData";
		$this->_requests["shutdown"] = "GnuBoat\ServiceShutdown";
		$this->_requests["logfiles"] = "GnuBoat\ServiceLogFiles";
		$this->_requests["map"] = "GnuBoat\ServiceMap";
		$this->_requests["replay"] = "GnuBoat\ServiceReplay";
		
		$this->_debug = $debug;
	}

	public function process()
	{
		$request = array_keys($this->_requests)[0];
		if(is_array($_GET) && array_key_exists("request", $_GET)){
			$request = $_GET["request"];
		}

		if(!array_key_exists($request, $this->_requests)){
			return Service::error("Request ". $request ." not implemented");
		}
		
		call_user_func(array(new $this->_requests[$request], "processRequest"), $this->_debug);
	}

	private $_requests;
	private $_debug;
}

?>
