<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Repository\ClassOfServices;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types\AbstractOptions;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types\BasedOptions;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types\ClassOfServicesOptions;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types\ServiceConfigurableOptions;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 30.09.19
 * Time: 12:06
 * Class ConfigOptions
 */
class ConfigOptionsType
{

    /**
     * @var null
     */
    protected $productId = null;

    /**
     * @var null
     */
    protected $type = null;

    /**
     * @var AbstractOptions
     */
    protected $configurableOptions = null;

    /**
     * @return null
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param $type
     * @return $this
     */
    public function setType($type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * @return null
     */
    public function getProductId()
    {
        return $this->productId;
    }

    /**
     * @param null $productId
     */
    public function setProductId($productId)
    {
        $this->productId = $productId;
    }

    /**
     * @return AbstractOptions
     */
    public function getConfigurableOptions()
    {
        return $this->configurableOptions;
    }

    /**
     * @throws \Exception
     */
    public function load()
    {
        switch($this->type)
        {
            case ClassOfServices::ZIMBRA_CONFIG_OPTIONS:
                $co = new ServiceConfigurableOptions($this->getProductId());
                break;
            case ClassOfServices::CLASS_OF_SERVICE_QUOTA:
                $co = new ClassOfServicesOptions($this->getProductId());
                break;
            default:
                $co = new BasedOptions($this->getProductId());
                break;
        }

        $this->configurableOptions = $co;

        return $this;
    }

}