<?php

namespace AutoAdmin\Bundle\Admin\Form;

use Symfony\Component\Validator\Constraints\NotBlank;

class FormOptionNormalizer
{
    public function normalize(array $options): array
    {
        if (!array_key_exists('error_bubbling', $options)) {
            $options['error_bubbling'] = false;
        }

        if (!empty($options['required'])) {
            $options['constraints'] = $options['constraints'] ?? [];
            if (count($options['constraints']) === 0) {
                $options['constraints'][] = new NotBlank();
            }
        }

        return $options;
    }
}
