<?php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotNull;

class FewoPriceType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $lodging = $options['lodging'];

        $builder
            ->add('perNight')
            ->add('flatPrice')
            ->add('season', EntityType::class, [
                'placeholder' => 'Bitte wählen',
                'class' => 'AppBundle\Entity\FewoSeason',
                'choices' => $lodging->getChoosableSeasons(),
                'constraints' => [
                    new NotNull(),
                    new Choice([
                            'choices' => $lodging->getChoosableSeasons()
                        ]
                    )]

            ])
        ;
    }
    
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'lodging' => null,
            'data_class' => 'AppBundle\Entity\FewoPrice'
        ));
        $resolver->setAllowedTypes('lodging', ['AppBundle\Entity\FewoLodging']);
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'appbundle_fewoprice';
    }


}
