<?php

namespace App\Libraries\Adapter\API;

use \App\Entities\HPILOEntity;

// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
{
	private $_entity = null;
	protected $_client = null;
	protected $_debug = false;
	protected function __construct($entity, $debug = false)
	{
		$this->_entity = $entity;
		$this->_debug = $debug;
	}
	abstract protected function getClient();
	abstract protected function requestURL(string $url, string $method, array $datas = []): object;
	final protected function getEntity()
	{
		return $this->_entity;
	}
	protected function getServerInfo($scheme = "https://", $delimeter = ":"): string
	{
		return $scheme . $this->getEntity()->getIP() . $delimeter . $this->getEntity()->getPort();
	}
	protected function getAccountInfo($type = 'basic'): array
	{
		//type: basic , digest
		return array($this->getEntity()->getID(), $this->getEntity()->getPassword(), $type);
	}
	protected function isSSLVerifiy(): bool
	{
		return getenv('hpilo.ssl') == 'true' ? true : false;
	}
	protected function getCookieFile()
	{
		return PATHS['API'] . getenv('api.cookie') ? getenv('api.cookie') : "api-cookie_" . date("Ymd") . ".log";
	}
	protected function getDebugFile()
	{
		return PATHS['API'] . getenv('api.debug') ? getenv('api.debug') : "api-debug_" . date("Ymd") . ".log";
	}

	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);
	}
}
