<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Helpers;


use ModulesGarden\Servers\ZimbraEmail\App\Traits\ServerParams;
use ModulesGarden\Servers\ZimbraEmail\App\Traits\ZimbraApiHandler;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 10.09.19
 * Time: 07:21
 * Class ZimbraManager
 */
class ZimbraManager
{
    use ServerParams;
    use ZimbraApiHandler;

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

        return $api;
    }

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

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

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

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

}