<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\ProductConfiguration\Helper;

use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\ConfigurableOptions;
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;
use ModulesGarden\Servers\ZimbraEmail\App\Services\ConfigurableOptions\Strategy\Types\AbstractOptions;

/**
 * Description of Config
 *
 * @author Mateusz Pawłowski <mateusz.pa@modulesgarden.com>
 */
class ConfigurableOptionsBuilder
{

    /**
     * @param ConfigurableOptions $configurableOptions
     * @param array $fieldsStatus
     * @return ConfigurableOptions
     */
    public static function build(ConfigurableOptions $configurableOptions, $fieldsStatus = [],AbstractOptions $options)
    {
        $allOptions = $options->getOptions();

        foreach ($fieldsStatus as $key => $field)
        {
            if ($field == "on")
            {
                $configurableOptions->addOption($allOptions[$key]);
            }
        }
        return $configurableOptions;
    }

    /**
     * @param ConfigurableOptions $configurableOptions
     * @return ConfigurableOptions
     */
    public static function buildAll(ConfigurableOptions $configurableOptions,AbstractOptions  $options)
    {
        foreach($options->getOptions() as $option)
        {
            /* @var $option Option*/
            $configurableOptions->addOption($option);
        }

        return $configurableOptions;
    }

    /**
     * @param $string
     * @param string $delimiter
     * @param string $addPrefix
     * @return string
     */
    private static function convertToCamelCase($string, $delimiter = "_", $addPrefix = ""){
        $explodeString = explode($delimiter, $string);
        $newString = "";

        foreach($explodeString as $value){
            if(empty($newString) && $addPrefix != ""){
                $newString = lcfirst($addPrefix);
            }elseif(empty($newString) && $addPrefix == ""){
                $newString = lcfirst($value);
                continue;
            }
            $newString .= ucfirst(($value));
        }
        return $newString;
    }


}
