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

namespace Kufer\KuferTools\Oeffentlich\LoginAnfordern\SendeLoginAnfordern;

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

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

    $request->email = \trim(\PostOperations::getVarValue('email'));
    $request->bemerkung = \trim(\PostOperations::getVarValue('bemerkung'));
    $request->userGroup = \trim(\PostOperations::getVarValue('userGroup'));

    $request->plz = \trim(\PostOperations::getVarValue('plz'));
    $request->strasse = \trim(\PostOperations::getVarValue('strasse'));
    $request->hausnummer = \trim(\PostOperations::getVarValue('hausnummer'));
    $request->ort = \trim(\PostOperations::getVarValue('ort'));

    $captcha = \Kufer\Web\Classes\Captchas\CaptchaFactory::getCaptcha4KuferTools();
    $request->captchaOk = $captcha->isValid(null, true, 'tedit', true);

    $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 SendeLoginAnfordernPresenter($pUseCaseResponse);
  }
}