<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap;

use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Repository\ClassOfServices;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateAccount;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateAccountAlias;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateAccountCos;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateAccountCosQuota;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateDistributionList;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateDomain;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateDomainAlias;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Delete\DeleteAccount;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Delete\DeleteAccountAlias;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Delete\DeleteDistributionList;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Delete\DeleteDomain;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Delete\DeleteDomainAlias;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Sso\ClientSingleSignOn;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Sso\ClientSingleSignOnToken;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\ChangePackage;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\ChangePackageConfigOptions;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\ChangePackageCosQuota;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\ChangePackageDedicatedCos;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\SuspendDomain;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateDomain;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UnsuspendDomain;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateAccount;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateAccountCosQuota;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateAccountPassword;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateAccountStatus;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update\UpdateDistributionList;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits\ApiClientHandler;

/**
 *
 * Class return supported services
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 03.10.19
 * Time: 13:15
 * Class Services
 */
class Services
{
    /**
     * API Client handler
     */
    use ApiClientHandler;

    /**
     * Services constructor.
     * @param Client $api
     */
    public function __construct(Client $api)
    {
        $this->setApi($api);
    }

    /**
     *
     * create account in zimbra, depends of product configuration
     * @param string $type
     * @return CreateAccount|CreateAccountCos|CreateAccountCosQuota
     */
    public function createAccount($type = ClassOfServices::CUSTOM_ZIMBRA)
    {
        switch ($type)
        {
            case ClassOfServices::CUSTOM_ZIMBRA:
                $service = new CreateAccount($this->getApi());
                break;
            case ClassOfServices::ZIMBRA_CONFIG_OPTIONS:
                $service = new CreateAccountCosQuota($this->getApi());
                break;
            case ClassOfServices::CLASS_OF_SERVICE_QUOTA:
                $service = new CreateAccountCosQuota($this->getApi());
                break;
            default:
                $service = new CreateAccountCosQuota($this->getApi());
                break;
        }

        return $service;
    }

    /**
     * create alias for account in zimbra
     *
     * @return CreateAccountAlias
     */
    public function createAccountAlias()
    {
        return new CreateAccountAlias($this->getApi());
    }

    /**
     * create distribution list (mailing list)
     *
     * @return CreateDistributionList
     */
    public function createDistributionList()
    {
        return new CreateDistributionList($this->getApi());
    }

    /**
     * create domain in zimbra (main domain for account)
     *
     *
     * @return CreateDomain
     */
    public function createDomain()
    {
        return new CreateDomain($this->getApi());
    }

    /**
     * create alias domain for account
     *
     * @return CreateDomainAlias
     */
    public function createDomainAlias()
    {
        return new CreateDomainAlias($this->getApi());
    }

    /**
     *
     * change product package
     *
     * @return ChangePackage
     */
    public function changePackages($type = ClassOfServices::CUSTOM_ZIMBRA)
    {
        switch ($type)
        {
            case ClassOfServices::CUSTOM_ZIMBRA:
                $service = new ChangePackage($this->getApi());
                break;
            case ClassOfServices::ZIMBRA_CONFIG_OPTIONS:
                $service = new ChangePackageConfigOptions($this->getApi());
                break;
            case ClassOfServices::CLASS_OF_SERVICE_QUOTA:
                $service = new ChangePackageCosQuota($this->getApi());
                break;
            default:
                $service = new ChangePackageDedicatedCos($this->getApi());
                break;
        }

        return $service;
    }

    /**
     * update account in panel
     *
     * @param string $type
     * @return UpdateAccount|UpdateAccountCosQuota
     */
    public function updateAccount($type = ClassOfServices::CUSTOM_ZIMBRA)
    {
        switch ($type)
        {
            case ClassOfServices::CUSTOM_ZIMBRA:
                $service = new UpdateAccount($this->getApi());
                break;
            case ClassOfServices::ZIMBRA_CONFIG_OPTIONS:
                $service = new UpdateAccount($this->getApi());
                break;
            case ClassOfServices::CLASS_OF_SERVICE_QUOTA:
                $service = new UpdateAccountCosQuota($this->getApi());
                break;
            default:
                $service = new UpdateAccount($this->getApi());
                break;
        }

        return $service;
    }

    /**
     * update account status
     *
     * @return UpdateAccountStatus
     */
    public function updateAccountStatus()
    {
        return new UpdateAccountStatus($this->getApi());
    }

    /**
     * change password service
     *
     * @return UpdateAccountPassword
     */
    public function updateAccountPassword()
    {
        return new UpdateAccountPassword($this->getApi());
    }

    /**
     * distribution (mailing) list update service
     *
     * @return UpdateDistributionList
     */
    public function updateDistributionList()
    {
        return new UpdateDistributionList($this->getApi());
    }

    /**
     * suspend domain in zimbra
     *
     * @return SuspendDomain
     */
    public function suspendDomain()
    {
        return new SuspendDomain($this->getApi());
    }

    /**
     * unsuspend domain
     *
     * @return UnsuspendDomain
     */
    public function unsuspendDomain()
    {
        return new UnsuspendDomain($this->getApi());
    }

    /**
     * delete account in panel
     *
     * @return DeleteAccount
     */
    public function deleteAccount()
    {
        return new DeleteAccount($this->getApi());
    }

    /**
     * delete domain & each related things
     *
     * @return DeleteDomain
     */
    public function deleteDomain()
    {
        return new DeleteDomain($this->getApi());
    }

    /**
     * delete account alias
     *
     * @return DeleteAccountAlias
     */
    public function deleteAccountAlias()
    {
        return new DeleteAccountAlias($this->getApi());
    }

    /**
     * delete distribution list (mailing list)
     *
     * @return DeleteDistributionList
     */
    public function deleteDistributionList()
    {
        return new DeleteDistributionList($this->getApi());
    }

    /**
     * delete domain alias
     *
     * @return DeleteDomainAlias
     */
    public function deleteDomainAlias()
    {
        return new DeleteDomainAlias($this->getApi());
    }

    /**
     *
     * return sso token
     * @return ClientSingleSignOnToken
     */
    public function clientSingleSignOnToken()
    {
        return new ClientSingleSignOnToken($this->getApi());
    }

}