<?php

namespace ModulesGarden\Servers\OpenXchange\App\Libs;

use Exception;
use ModulesGarden\Servers\OpenXchange\App\Models\ProductConfiguration;

class Api
{
    protected $params;
    protected $result = [];
    protected $error; 
    protected $host;
    protected $ssl;
    protected $path;
    protected $username;
    protected $password;
    protected $requestMethod;
    protected $postfields;
    protected $settings;
    public $client;

    public function __construct($params)
    {
        $this->params = $params;
        $this->setProductSettings();
        $this->setCredentials();
        $this->setClient();
    }

    protected function setCredentials()
    {
        $this->ssl      = $this->params['serversecure'] ? 'https://' : 'http://';
        $this->host     = $this->params['serverhostname'];
        $this->username = $this->params['serverusername'];
        $this->password = $this->params['serverpassword'];
    }

    public function setProductSettings()
    {
        try{
            $this->settings = ProductConfiguration::config($this->params['packageid']);
        } catch(\Exception $e)
        {
            // do nothing;
        }
        
        return $this;
    }

    public function getSettings()
    {
        return $this->settings;
    }

    public function getParams()
    {
        return $this->params;
    }

    public function getEndpoint()
    {
        return $this->endpoint;
    }

    public function getRequestMethod()
    {
        return $this->requestMethod;
    }

    public function getPostfields()
    {
        return $this->postfields;
    }

    public function getHost()
    {
        return $this->host;
    }
    
    public function getSSL()
    {
        return $this->ssl;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function getPassword()
    {
        return $this->password;
    }
}
