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

namespace Kufer\Web\KuferTools\Dozent\KursUebersicht\Detailsreiter\Termine\TerminDirectAbrechnen;

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

  protected function getRequestObj()
  {
    $requestObj = new SendAbrechnungRequest();
    $requestObj->knr = \GetOperations::getVarValue('knr');
    $ktids = \GetOperations::getVarValue('ktids');
    $requestObj->kursTagIds = explode(':', $ktids);
    $requestObj->kursTagIdsStr = $ktids;

    $requestObj->abzurechnendeKurstage = array();
    $requestObj->zuruekzunehmendeKurstage = array();
    foreach ($requestObj->kursTagIds as $ktid) {
      if (\PostOperations::isDefined('abrechnen_kt_' . $ktid)) {
        $requestObj->abzurechnendeKurstage[] = $ktid;
      }
      if (\PostOperations::isDefined('zurueck_kt_' . $ktid)) {
        $requestObj->zuruekzunehmendeKurstage[] = $ktid;
      }
    }

    
    $action = \GetOperations::getVarValue('action');

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

  protected function getControllerToForward($pUseCaseResponse)
  {
    return new TerminAbrechnenNachAbsendenController($pUseCaseResponse);
  }

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