<?php

namespace App\Form;

use App\Entity\Category;
use App\Entity\Country;
use App\Entity\Currency;
use App\Entity\Domain;
use App\Entity\Prospect;
use App\Tools\DBAL\ProspectStatus;
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\EmailType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProspectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('status', ChoiceType::class, [
                'label' => 'Type',
                'choices' => ProspectStatus::all(),
            ])
            ->add('domain', EntityType::class, [
                'class' => Domain::class,
                'choice_value' => 'id',
                'choice_label' => 'url',
            ])
            ->add('categories', EntityType::class, [
                'class' => Category::class,
                'choice_label' => 'title',
                'by_reference' => false,
                'multiple' => true,
            ])
            ->add('name', TextType::class, [
                'label' => 'Name',
                'required' => false,
            ])
            ->add('phone', TextType::class, [
                'label' => 'Phone',
                'required' => false,
            ])
            ->add('mobile', TextType::class, [
                'label' => 'Mobile',
                'required' => false,
            ])
            ->add('email', EmailType::class, [
                'label' => 'Email',
                'required' => false,
            ])
            ->add('paypalEmail', EmailType::class, [
                'label' => 'PayPal Email',
                'required' => false,
            ])
            ->add('comment', TextareaType::class, [
                'label' => 'Comment',
                'required' => false,
            ])
            ->add('type', TextType::class, [
                'label' => 'Type',
            ])
            ->add('guidelines', UrlType::class, [
                'label' => 'Guidelines URL',
                'required' => false,
            ])
            ->add('score', IntegerType::class, [
                'label' => 'Score',
                'required' => false,
                'empty_data' => '50',
            ])
            ->add('country', EntityType::class, [
                'class' => Country::class,
                'label' => 'Targeted country',
                'choice_value' => 'id',
                'choice_label' => 'title',
                'required' => true,
            ])
            ->add('currency', EntityType::class, [
                'class' => Currency::class,
                'label' => 'Currency',
                'choice_value' => 'id',
                'choice_label' => 'title',
                'required' => true,
            ]);
    }

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