<?php

declare(strict_types=1);

namespace App\Service\Liform\Extension;

use App\Service\ProspectService;
use Limenius\Liform\Transformer\ExtensionInterface;
use Symfony\Component\Form\FormInterface;

final class DataListExtension implements ExtensionInterface
{
    /**
     * @var ProspectService
     */
    private $prospectService;

    public function __construct(ProspectService $prospectService)
    {
        $this->prospectService = $prospectService;
    }

    /**
     * @param FormInterface $form
     * @param array         $schema
     *
     * @return array
     */
    public function apply(FormInterface $form, array $schema)
    {
        if ('prospect' === $form->getRoot()->getName() && 'type' === $form->getName()) {
            $schema['enum'] = $schema['enum_titles'] = $this->prospectService->getTypes();
        }

        return $schema;
    }
}
