<?php

namespace App\Libraries\Adapter\API;

// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
{
	protected $_client = null;
	protected $_serverInfo = array();
	protected $_accountInfo = array();
	protected $_debug = false;
	protected function __construct($debug = false)
	{
		$this->_debug = $debug;
	}
	abstract protected function getClient();
	abstract protected function requestURL(string $url, string $method, array $datas = []): object;
	final public function setServerInfo($ip, $port)
	{
		$this->_serverInfo['ip'] = $ip;
		$this->_serverInfo['port'] = $port;
	}
	final protected function getServerInfo($scheme = "https://", $delimeter = ":"): string
	{
		return $scheme . $this->_serverInfo['ip'] . $delimeter . $this->_serverInfo['port'];
	}
	final public function setAccountInfo($id, $password)
	{
		$this->_serverInfo['id'] = $id;
		$this->_serverInfo['password'] = $password;
	}
	final protected function getAccountInfo($authType = 'basic'): array
	{
		//type: basic , digest
		return array($this->_serverInfo['id'], $this->_serverInfo['password'], $authType);
	}

	final public function get(string $url): object
	{
		return $this->requestURL($url, 'GET');
	}
	final public function post(string $url, array $datas): object
	{
		return $this->requestURL($url, 'POST', $datas);
	}
}
