<?php

namespace App\Form\Type;

use App\Entity\GlobalParameter;
use App\Entity\Prestataire;
use App\Entity\Reconversion;
use App\Entity\Siege;
use App\Enum\MoyenEnum;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ReconversionFormType extends FluxFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('moyen', HiddenType::class, [
                'data' => MoyenEnum::MOYEN_AUTRE,
            ])
            ->add('tauxreconversion', HiddenType::class, [
                'data' => (!empty($this->session->get('_prestagere')->getTauxreconversion()) ? $this->session->get('_prestagere')->getTauxreconversion() : $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::RECONVERSION_PRESTATAIRE)),
            ])
            ->add('expediteur', HiddenType::class, [
                'data' => $this->session->get('_prestagere')->getId(),
                'data_class' => null,
                'entity_class' => Prestataire::class,
                'em' => $this->em,
            ])
            ->add('destinataire', HiddenType::class, [
                'data' => 1,
                'data_class' => null,
                'entity_class' => Siege::class,
                'em' => $this->em,
            ])
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'class' => Reconversion::class,
        ]);
    }

    public function getParent()
    {
        return FluxFormType::class;
    }

    public function getBlockPrefix()
    {
        return 'formReconversion';
    }
}
