<?php


namespace App\Components\Forms;


use App\Model\Facades\GameFacade;
use App\Model\Translator;

class PublisherFormFactory extends BaseFormFactory
{
    /** @var GameFacade */
    protected $gameFacade;

    public function __construct(Translator $translator, GameFacade $gameFacade)
    {
        parent::__construct($translator);
        $this->gameFacade = $gameFacade;
    }


    public function create() : BootstrapForm
    {
        $form = parent::create();
        $form->addText('name', 'Publisher name:')
            ->addRule(BootstrapForm::FILLED, 'Please fill publisher name.');
        $form->addSubmit('submit', 'Submit');

        return $form;
    }


    public function formSucceeded(BootstrapForm $form, $values)
    {
        $this->gameFacade->getPublisherWriter()->createPublisher($values->name);
    }
}