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

namespace Kufer\Web\KuferTools\Mitarbeiter\AdressInfo\NewAdress\HandleAdressInsert;

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

  protected function getRequestObj()
  {
    $requestObj = new HandleAdressInsertRequest();
    $requestObj->anr = \GetOperations::getVarValue('anr', -1);
    $requestObj->adrInsert = \GetOperations::isDefined('adressInsert');

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

    $action = $this->getActionVal();

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

  protected function getPresenter($pUseCaseResponse)
  {
    return null; 
  }

  protected function getControllerToForward($pUseCaseResponse)
  {
    if ($pUseCaseResponse->anr == -1) {
      header('Location: index.php?tool_id=33');
    } else {
      header('Location: index.php?tool_id=33&action=adressdetails&anr=' . $pUseCaseResponse->anr);
    }

    die();
  }
}