<?php


namespace App\Components\Forms;


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

class PlatformFormFactory 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', 'Platform name:')
            ->addRule(BootstrapForm::FILLED, 'Please fill platform name.');
        $form->addDatePicker('releaseDate', 'Released on:')
            ->addRule(BootstrapForm::FILLED, 'Please select platform release date.');
        $form->addSubmit('submit', 'Submit');

        return $form;
    }


    public function formSucceeded(BootstrapForm $form, $values)
    {
        $this->gameFacade->getPlatformWriter()->createPlatform($values->name, $values->releaseDate);
    }
}