<?php

namespace App\Form;

use App\Entity\Content;
use App\Entity\Link;
use App\Entity\Negotiation;
use App\Entity\Prospect;
use App\Tools\DBAL\EnumLinkStatusType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class LinkType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('url', TextType::class, [
                'label' => 'URL',
            ])
            ->add('status', ChoiceType::class, [
                'label' => 'Status',
                'choices' => EnumLinkStatusType::getValues(),
                'required' => false,
            ])
            ->add('prospect', EntityType::class, [
                'class' => Prospect::class,
                'choice_value' => 'id',
                'choice_label' => 'name',
            ])
            ->add('content', EntityType::class, [
                'class' => Content::class,
                'choice_value' => 'id',
                'choice_label' => 'title',
            ])
            ->add('negotiation', EntityType::class, [
                'class' => Negotiation::class,
                'choice_value' => 'id',
                'choice_label' => 'id',
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Link::class,
            'allow_extra_fields' => true,
            'csrf_protection' => false,
        ]);
    }
}
