<?php
include_once("core/Plugin_Api.php");
include_once("core/LibOverride/genTokenOptions.php");

class App{
	
	protected $openstack;
	protected $pluginsApi;
	protected $tokenClass;
	protected $tokenPost;
	protected $output;

	public function __construct($args){

		$this->tokenPost = NULL;
		$this->tokenClass = new genTokenOptions($args);
		$this->openstack = new OpenStack\OpenStack([]);
		$this->pluginsApi = plugin_api::getInstance();
		$this->output = array();

	}
	
	public function setToken($token){
		
		$this->tokenPost = $token;
		$this->tokenClass->loadBackup($his->tokenPost);
		
	}
	
	public function getLibClass($service){
		
		switch($service){
			case "Identity":
				if($tokenPost == NULL) $tokenClass->genIdentityToken();
				$opt = $tokenClass->getOptions($service);
				return $this->openstack->identityV3($opt);
				break;
		}
		
	}
	
	public function authenticate(){
		
		try{
			$this->tokenClass->genIdentityToken();
			$this->tokenClass->genComputeToken();
			$this->tokenClass->genImageToken();
			$this->tokenClass->genNetworkToken();
			
			$this->setOutput("token", $this->tokenClass->getBackup());
		}catch(Exception $e){
			echo $e;
			exit();
		}
		
	}
	
	public function setOutput($key, $out){
		
		$this->output[$key] = $out;
		
	}
	
	public function show(){
		echo json_encode($this->output);
	}
	
}