<?php

require __DIR__ . '/../api/user.php';


return [

	'routes' => [
		[
			'pattern' => 'kp/kangaworld/v1',
			'method'  => 'POST',
			'action'  => function() {

				$response = array();
				$response['result'] = 'false';
				$response['reason'] = 'Unknown error.';

				// Although Kirby only allows admins this far, we may have a
				//configurable  sub-role for API access later.
				if (kirby()->user()->role()->id() == 'admin') {

					switch (get('command')) {

						case 'API_AVAILABLE':
							$response['result'] = 'true';
							$response['reason'] = 'API Available.';
							break;

						case 'USER_CREATE':
							kpApiUserCreate(get('first'), get('last'), get('user'), get('email'), get('pass'), $response);
							break;

						default:
							$response['reason'] = 'Invalid command.';
							break;
					}

				} else {
					$response['reason'] = 'Unauthorized.';
				}

				return $response;
			}

		]
	]

];

?>
