<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

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

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

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

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

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

    $action = $this->getActionVal();

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

  protected function createNewRequestObj(): WunschterminNeuRequest
  {
    return new WunschterminNeuAbsendenRequest();
  }

  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;
  }
}