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

namespace Kufer\Web\KuferTools\Oeffentlich\LoginAnfordern\SendeAutoLoginAnfordern;

class SendeAutoLoginAnfordernController extends \Kufer\Web\KuferTools\Basis\Controller\Controller
{
  protected function getUseCase(): \Kufer\Web\KuferTools\Basis\UseCase\UseCase
  {
    return new SendeAutoLoginAnfordernUseCase(
      $this->getRequestObj(),
      \ToolSettingsAPI::getToolSettings(0)
    );
  }

  protected function getRequestObj()
  {
    $request = new SendeAutoLoginAnfordernRequest();
    $request->name = \trim(\PostOperations::getVarValue('name'));
    $request->vorname = \trim(\PostOperations::getVarValue('vorname'));
    $request->email = \trim(\PostOperations::getVarValue('email'));
    $request->geschlecht = \trim(\PostOperations::getVarValue('geschlecht'));

    $captcha = \Kufer\Web\Classes\Captchas\CaptchaFactory::getCaptcha4KuferTools();
    $request->captchaOk = $captcha->isValid(null, true, 'tedit', true);
    $request->passwort = \FilterBasis::filterPasswort(\PostOperations::getVarValue('password'));
    $request->passwortWiederholt = \FilterBasis::filterPasswort(\PostOperations::getVarValue('password_repeat'));

    $request->benutzergruppe = \PostOperations::getVarValue('benutzergruppe');

    $request->dseZustimmung = \PostOperations::getVarValue('dseZustimmung', false);
    $request->freiesPflichtfeldZustimmung = \PostOperations::getVarValue('freiesPflichtfeldZustimmung', false);

    $action = $this->getActionVal();

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

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