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

namespace Kufer\Web\KuferTools\Dozent\KursUebersicht\Detailsreiter\Termine\TerminAbrechnenMoenchengladBildungswerk\Senden;

use Kufer\Web\KuferTools\Dozent\KursUebersicht\KursDetails\DozKursDetailsController;
use Kufer\Web\KuferTools\Dozent\KursUebersicht\Detailsreiter\Termine\TerminAbrechnenMoenchengladBildungswerk\TerminAbrechnenController;

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

  
  protected function getRequestObj()
  {
    $result = new SendeTerminAbrechnenRequest();
    $ktids = \GetOperations::getVarValue('ktids');
    $result->ktIds = array_map(static function($str) {
      return (int)$str;
    }, explode(':', $ktids));
    $result->hinweise = \PostOperations::getVarValue('hinweise');
    $result->accepted = \PostOperations::isDefined('accept');

    return $this->handleXsrf($result, $this->getActionVal(), $ktids);
  }

  protected function getControllerToForward($pUseCaseResponse)
  {
    if ($pUseCaseResponse->error) {
      return new TerminAbrechnenController($pUseCaseResponse);
    }

    $result = new DozKursDetailsController();
    $result->pdfbinary = $pUseCaseResponse->rawpdf;
    $result->pdftitle = 'Honorarabrechnung';

    return $result;
  }

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