<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types;
use ModulesGarden\Servers\ZimbraEmail\App\Helpers\ZimbraManager;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\ClassOfService;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Repository;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Helper\TypeConstans;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Models\Option;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Models\SubOption;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 30.09.19
 * Time: 12:20
 * Class ServiceConfigurableOptions
 */
class ServiceConfigurableOptions extends BasedOptions
{

    /**
     * @return mixed|BasedOptions|void
     */
    public function initContent()
    {
        parent::initContent();

        $api     = (new ZimbraManager())->getApiByProduct($this->getProductId());
        $repository = new Repository($api->soap);
        $classOfServices = $repository->cos->all();


        /**
         *
         */
        $option  = new Option('cos', 'Class Of Service', TypeConstans::DROPDOWN);
        foreach($classOfServices as $cos)
        {
            /* @var $cos ClassOfService */
            $option->addSubOption(new SubOption($cos->getId(), $cos->getName()));
        }

        $this->addOption($option);
    }

}