<?php

declare(strict_types=1);

namespace App\Framework\FormGenerator;

/**
 * Complete Schema eines generierten Forms aus Request Object
 */
final readonly class RequestFormSchema
{
    /**
     * @param FormFieldSchema[] $fields
     */
    public function __construct(
        public string $requestClass,
        public array $fields
    ) {
    }

    public function getFieldByName(string $name): ?FormFieldSchema
    {
        foreach ($this->fields as $field) {
            if ($field->name === $name) {
                return $field;
            }
        }

        return null;
    }

    public function hasField(string $name): bool
    {
        return $this->getFieldByName($name) !== null;
    }
}
