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

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

class HandleAdressUpdateController extends \Kufer\Web\KuferTools\Basis\Controller\ToolController
{
  protected function getUseCase(): \Kufer\Web\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\Web\KuferTools\Utils\WssHandler(
      HandleAdressUpdateUseCase::getToolId(),
      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 {
      $guidPart = !empty($pUseCaseResponse->aguid) ? '&aguid=' . $pUseCaseResponse->aguid : '';
      header('Location: index.php?tool_id=33&action=adressdetails&anr=' . $pUseCaseResponse->anr . $guidPart);
    }

    die();
  }
}