<?php

namespace ThurData\Servers\KerioEmail\App\Helpers;


use ThurData\Servers\KerioEmail\App\Traits\ServerParams;
use ThurData\Servers\KerioEmail\App\Traits\KerioApiHandler;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 10.09.19
 * Time: 07:21
 * Class KerioManager
 */
class KerioManager
{
    use ServerParams;
    use KerioApiHandler;

    /**
     * @param $id
     * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Api
     */
    public function getApiByHosting($id)
    {
        $serverParams = $this->getServerParamsByHostingId($id);
        $api = $this->getApi()->setParams($serverParams);

        return $api;
    }

    /**
     * @param $id
     * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Api
     */
    public function getApiByProduct($id)
    {
        $serverParams = $this->getServerParamsByProductId($id);
        $api = $this->getApi()->setParams($serverParams);
        return $api;
    }

    /**
     * @param $id
     * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Api
     */
    public function getApiByServer($id)
    {
        $serverParams = $this->getServerParamsById($id);
        $api = $this->getApi()->setParams($serverParams);
        return $api;
    }

    /**
     * @param $id
     * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository
     */
    public function getRepositoryByHosting($id)
    {
        return $this->getRepository($this->getApiByHosting($id)->soap);
    }

    /**
     * @param $id
     * @return \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository
     */
    public function getRepositoryByProduct($id)
    {
        return $this->getRepository($this->getApiByProduct($id)->soap);
    }

}