<?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\Form\AttributesCeneoForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\CategoriesCeneoForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\CategoriesNokautForm;
use DropshippingExportFreeVendor\WPDesk\Forms\Form\FormWithFields;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\CeneoExportMapperForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\ExportMapperForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\GmcExportMapperForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\HomebookExportMapperForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\NokautExportMapperForm;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Form\UcpSettingsForm;
class FormFactory
{
    /**
     * @var DependencyResolverInterface
     */
    private $resolver;
    public function __construct(DependencyResolverInterface $dependency_resolver)
    {
        $this->resolver = $dependency_resolver;
    }
    public function create_by_class_name(string $class_name): FormWithFields
    {
        $forms = $this->get_all_settings_forms();
        foreach ($forms as $form) {
            if ($class_name === $form) {
                return $this->resolver->resolve($form);
            }
        }
        throw new RuntimeException('Error, form clasname ' . $class_name . ' not found.');
    }
    public function create_by_id($id): FormWithFields
    {
        $forms = $this->get_all_settings_forms();
        foreach ($forms as $form) {
            if ($id === $form::get_id()) {
                return $this->resolver->resolve($form);
            }
        }
        throw new RuntimeException('Error, form id ' . $id . ' not found.');
    }
    private function get_all_settings_forms(): array
    {
        return [AttributesCeneoForm::class, CategoriesCeneoForm::class, CategoriesNokautForm::class, ExportMapperForm::class, CeneoExportMapperForm::class, NokautExportMapperForm::class, HomebookExportMapperForm::class, GmcExportMapperForm::class, UcpSettingsForm::class];
    }
}
