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

namespace Kufer\KuferTools\Oeffentlich\Startseite;

class ShowStartseiteController extends \Kufer\KuferTools\Basis\Controller\Controller
{
  protected function getUseCase(): \Kufer\KuferTools\Basis\UseCase\UseCase
  {
    return new ShowStartseiteUseCase(
      $this->getRequestObj()
    );
  }

  protected function getRequestObj()
  {
    $result = new ShowStartseiteRequest();
    $forward_to_tool = \GetOperations::getVarValue('forward_to_tool');
    if ($forward_to_tool !== '' && \CleanOperations::isInt($forward_to_tool)) {
      $result->forward_to_tool = (int)$forward_to_tool;
      $result->forward_to_id = \GetOperations::getVarValue('forward_to_id');
    }

    return $result;
  }

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

  protected function getControllerToForward($pUseCaseResponse)
  {
    $tool0Settings = \ToolSettingsAPI::getToolSettings(0);
    if (($tool0Settings->forwardToWillkommenWennAngemeldet || !is_null($pUseCaseResponse->forward_to_tool)) && \SessionOperations::isWtUserLoggedIn()) {
      return new \Kufer\KuferTools\Oeffentlich\DoLogin\DoLoginController();
    } else {
      return null;
    }
  }
}