<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Dependency\Resolver\Abstraction\DependencyResolverInterface;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\CeneoConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\PriceCompareConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Exception\PriceCompareConfigException;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\CustomCsvConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\CustomXmlConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\GmcConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\HomebookConfig;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\PriceCompare\Config\NokautConfig;
class PriceCompareFactory
{
    /**
     * @var DependencyResolverInterface
     */
    private $resolver;
    public function __construct(DependencyResolverInterface $dependency_resolver)
    {
        $this->resolver = $dependency_resolver;
    }
    public function get_config_by_id(string $id): PriceCompareConfig
    {
        foreach ($this->get_configs() as $config) {
            if ($config->get_id() === $id) {
                return $config;
            }
        }
        throw new PriceCompareConfigException('Config id: ' . $id . ' is not supported');
    }
    public function get_configs(): array
    {
        $result = [];
        foreach ($this->get_all_configs() as $config) {
            $result[] = $this->resolver->resolve($config);
        }
        return $result;
    }
    private function get_all_configs(): array
    {
        return [CustomXmlConfig::class, CustomCsvConfig::class, CeneoConfig::class, NokautConfig::class, HomebookConfig::class, GmcConfig::class];
    }
}
