<?php

declare(strict_types=1);

namespace Apexl\Io\FormBuilder\ComponentFactories;

use Apexl\Io\Component\Factories\GenericComponentFactory;
use Apexl\Io\FormBuilder\Components\Form;

final readonly class FormComponentFactory
{
    public function __construct(private GenericComponentFactory $componentFactory) {}

    /** @var class-string<Form> $class */
    public function make(string $class = Form::class): Form
    {
        \Apexl\Io\assertInstanceOf($class, Form::class);

        /** @var Form $form */
        $form = $this->componentFactory->make($class);

        $form->init();

        return $form;
    }
}