<?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:19
 * Class ClassOfServicesOptions
 */
class ClassOfServicesOptions extends BasedOptions
{
    const COS_CONFIG_OPT_PREFIX = 'cosQuota_';

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


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

        /**
         * add quantity config options Class of Services
         */
        foreach ($classOfServices as $cos)
        {
            /* @var $cos ClassOfService */
            $key = self::COS_CONFIG_OPT_PREFIX.$cos->getId();
            $name = sprintf($this->getLang()->absoluteT('COS %s with quota %s MB'), $cos->getName(), $cos->getMbMailQuote());

            $option  = new Option($key, $name, TypeConstans::QUANTITY);
            $subName = sprintf($this->getLang()->absoluteT('COS %s MB'),  $cos->getMbMailQuote());
            $option->addSubOption(new SubOption('1', $subName));
            $this->addOption($option);
        }

    }
}