<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Config;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Data\Abstraction\DataTypeInterface;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Container\ParameterContainer;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Config\Abstraction\ConfigInterface;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Config\Abstraction\AbstractSingleConfig;
/**
 * Class Config, stores all merged data from single configurations and shares data access methods.
 *
 * @package WPDesk\Library\DropshippingExport\Infrastructure\Config
 */
final class Config implements ConfigInterface
{
    /**
     * @var ParameterContainer
     */
    private $parameter_container;
    public function __construct()
    {
        $this->parameter_container = new ParameterContainer([]);
    }
    public function get_param(string $key): DataTypeInterface
    {
        return $this->parameter_container->get_param($key);
    }
    public function register_config(array $config)
    {
        foreach ($config as $conf) {
            if ($conf instanceof AbstractSingleConfig) {
                $conf->set_config($this);
                $this->parameter_container->add_params([$conf->get_id() => $conf->get()]);
            } else {
                throw new Exception\ConfigException('Config object should implements AbstractSingleConfig');
            }
        }
    }
}
