<?php

namespace ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions;

use Exception;
use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Models\Option;

/**
 * Description of ConfigurableOptions
 *
 * @autor ThurData <info@thurdata.ch>
 */
class ConfigurableOptions extends Abstracts\AbstractConfigurableOptions
{
    /*
     * Create New Configurable Optoions group
     * 
     * @throw \Exception
     */

    public function create()
    {
        if ($this->checkExistAssignedOptionsGroup())
        {
            throw new Exception('Configurable options already exist.');
        }
        $this->addGroup();
        $this->buildOptions();
    }

    /*
     * Save additional fields 
     * 
     * 
     * Return true, if mmethod create a new configurable group;
     * 
     * @return boolean $group;
     * 
     */

    public function createOrUpdate()
    {
        $group = $this->addGroup();
        $this->buildOptions();
        return $group;
    }

    public function show()
    {
        return $this->showOptions();
    }

    /*
     *  Add Option to group 
     * 
     * @param \ThurData\Servers\KerioEmail\App\Service\ConfigurableOptions\Models\Option $option
     */

    public function addOption(Option $option)
    {
        $this->options[] = $option;

        return $this;
    }

}
