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

namespace Kufer\KuferTools\Mitarbeiter\AdressInfo\UpdateAdress\HandleAdressUpdate;

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

  protected function getRequestObj()
  {
    $requestObj = new HandleAdressUpdateRequest();
    $requestObj->anr = \GetOperations::getVarValue('anr', -1);
    $requestObj->aguid = \GetOperations::getVarValue('aguid', null);
    $requestObj->adressUpdate = \GetOperations::isDefined('adressUpdate');

    $wssHandler = new \Kufer\KuferTools\Utils\WssHandler(HandleAdressUpdateUseCase::getToolSectionId(), HandleAdressUpdateUseCase::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 . (!empty($pUseCaseResponse->aguid) ? '&aguid=' . $pUseCaseResponse->aguid : ''));
    }

    return null;
  }
}