<?php
namespace ThurData\Servers\KerioEmail\App\Http\Actions;

use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Api;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Client;
use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
use ThurData\Servers\KerioEmail\Api\KerioWhmcs;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 27.08.19
 * Time: 14:54
 * Class TestConnection
 */
class TestConnection extends AddonController
{

    use ExtensionsCheckerTrait;
    /**
     *
     *
     * @param null $params
     * @return array
     */
    public function execute($params = null)
    {
        /**
         * API Connection
         */

        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
        try {
            $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
            $serverInfo = $api->getServerInfo();
            $api->logout();
        } catch (KerioApiException $error) {
            return ['error' => $error->getMessage()];
        }             
        /**
         * check if connected and return true
         */
        if($serverInfo)
        {
            return ['success' => true];
        }

    }
}