<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Dozent\Wunschtermine\NeuAbsenden;

use Kufer\Web\KuferTools\Dozent\Wunschtermine\Neu;

class WunschterminNeuAbsendenController extends Neu\WunschterminNeuController
{
  protected function getUseCase(): \Kufer\KuferTools\Basis\UseCase\UseCase
  {
    return new WunschterminNeuAbsendenUseCase($this->getRequestObj());
  }

  protected function getRequestObj()
  {
    $result = parent::getRequestObj();

    $wssHandler = new \Kufer\KuferTools\Utils\WssHandler(WunschterminNeuAbsendenUseCase::getToolSectionId(), WunschterminNeuAbsendenUseCase::getUser());
    $result->columnValues = $wssHandler->getColumnValuesFromPost();
    $result->wssHandler = $wssHandler;

    $action = $this->getActionVal();

    return $this->handleXsrf($result, $action);
  }

  protected function getPresenter($pUseCaseResponse)
  {
    return new WunschterminNeuAbsendenPresenter($pUseCaseResponse);
  }

  protected function getControllerToForward($pUseCaseResponse)
  {
    if (!empty($pUseCaseResponse->wrongFields) || is_null($pUseCaseResponse->wunschtermin->id)) {
      return new Neu\WunschterminNeuController($pUseCaseResponse->wunschtermin);
    }

    return null;
  }
}