<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Factory;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Dependency\Resolver\Abstraction\DependencyResolverInterface;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Validator\DataFormat\CsvDataFormatValidator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Validator\DataFormat\DataFormatValidator;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Validator\DataFormat\XmlDataFormatValidator;
use RuntimeException;
/**
 * Class DataFormatValidatorFactory, factory for data format validators.
 *
 * @package WPDesk\Library\DropshippingExport\Factory
 */
class DataFormatValidatorFactory
{
    /**
     * @var DependencyResolverInterface
     */
    private $resolver;
    public function __construct(DependencyResolverInterface $dependency_resolver)
    {
        $this->resolver = $dependency_resolver;
    }
    public function create_validator(string $mime_type): DataFormatValidator
    {
        $validators = $this->get_all_validators();
        foreach ($validators as $validator) {
            if ($validator::is_mime_type_supported($mime_type)) {
                return $this->resolver->resolve($validator);
            }
        }
        throw new RuntimeException('File mime type ' . $mime_type . ' is not supported.');
    }
    private function get_all_validators(): array
    {
        return [XmlDataFormatValidator::class, CsvDataFormatValidator::class];
    }
}
