<?php
namespace ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\Types;
use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Helper\TypeConstans;
use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Models\Option;
use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Models\SubOption;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 30.09.19
 * Time: 12:20
 * Class ServiceConfigurableOptions
 */
class ServiceConfigurableOptions extends BasedOptions
{

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

        $api     = (new KerioManager())->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);
    }

}