<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Dependency\Resolver\Abstraction\DependencyResolverInterface;
use RuntimeException;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Converter\File\CsvFileConverter;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Converter\File\XmlFileConverter;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Converter\File\FileConverterInterface;
/**
 * Class FileConverterFactory, file converter factory.
 *
 * @package WPDesk\Library\DropshippingExport\Factory
 */
class FileConverterFactory
{
    /**
     * @var DependencyResolverInterface
     */
    private $resolver;
    public function __construct(DependencyResolverInterface $dependency_resolver)
    {
        $this->resolver = $dependency_resolver;
    }
    public function create_by_data_format(string $format, array $parameters = []): FileConverterInterface
    {
        $data_converters = $this->get_all_product_data_converters();
        foreach ($data_converters as $data_converter) {
            if ($format === $data_converter::get_supported_data_format()) {
                return $this->resolver->resolve($data_converter, $parameters);
            }
        }
        throw new RuntimeException('Error, product data converter for format ' . $format . ' not found.');
    }
    private function get_all_product_data_converters(): array
    {
        return [CsvFileConverter::class, XmlFileConverter::class];
    }
}
