<?php
namespace App\Form\Actors;

use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use App\Entity\ActorEntity;
use App\Form\AbstractFormManager;

class ActorAddForm extends AbstractFormManager
{

    /**
     * Get the actor in the form data
     *
     * @return ActorEntity
     */
    public function getActor(): ActorEntity
    {
        $data = $this->form->getData();
        $actor = new ActorEntity();
        $actor->generateId();
        $actor->setFirstName($data['firstName']);
        $actor->setLastName($data['lastName']);
        $actor->setNickname($data['nickname'] ?? "");
        $actor->setFollowed($data['followed']);

        return $actor;
    }

    /**
     * {@inheritdoc}
     */
    public function getTemplate(): string
    {
        return '_includes/html/form/actors/add.html.twig';
    }

    /**
     * {@inheritdoc}
     */
    protected function addFields($formBuilder, $options): void
    {
        $formBuilder->add('firstName', TextType::class, [
            'required' => true
        ])
            ->add('lastName', TextType::class, [
            'required' => true
        ])
            ->add('nickname', TextType::class, [
            'required' => false
        ])
            ->add('followed', CheckboxType::class, [
            'required' => false
        ])
            ->add('submit', SubmitType::class);
    }
}