<?php

namespace App\Form\Type;

use App\Entity\VenteEmlcPrestataire;
use App\Entity\Prestataire;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class VenteEmlcPrestataireFormType extends VenteEmlcFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if (empty($this->security) || empty($this->security->getUser())) {
            throw new \Exception("[FORM VENTE EMLC PRESTATAIRE] Opération impossible !");
        }
        $builder
            ->add('destinataire', EntityType::class, array(
                'class' => Prestataire::class,
                'choices' =>  $this->em->getRepository(Prestataire::class)->findBy(array('enabled' => true, 'mlc' => false), array('raison'=> 'ASC')),
                'placeholder' => 'Prestataire',
                'required' => true,
                'label' => 'Prestataire :',
            ))
            ->add('reference', HiddenType::class, array(
                'data' => 'Achat eMLC Prestataire'
            ))
        ;
    }

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

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

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