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


namespace Kufer\Web\KuferTools\Basis\KursUebersicht\Detailsreiter\Honorar\AddDozent;


use Kufer\KuferTools\Utils\DozKursHandler\DozKursInserter as DozKursInserter;




abstract class AddDozentUseCase extends \Kufer\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request, $response = null)
  {
    parent::__construct($request, $response ?? new AddDozentResponse());
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess()) {
      
      return false;
    }
    
    elseif (!$this->request->isXsrfOk && !$this->request->isRefresh) {
      return false;
    }
    
    
    
    
    
    return true;
  }

  public function action()
  {
    $allgSettings = \AllgSettingsAPI::getAllgSettings();
    $dmzBetrieb = $this->session->isReplikat() && $allgSettings->dmzEnabled;
    

    $statusMessageContainer = null;

    
    $dozKursInsertHandler = new DozKursInserter($this->request, false);
    $dozKursInsertHandler->setDmzBetrieb($dmzBetrieb);

    
    if (!$this->request->isRefresh) {
      $dozKursInsertHandler->doInsert($this->request->dozId);
      $statusMessageContainer = $dozKursInsertHandler->getStatusMessageContainer();
    }

    return $this->getResponse($statusMessageContainer);
  }

  protected function getResponse($pStatusMessageContainer)
  {
    $this->handleResponseStrategies();
    
    $this->response->statusMessageContainer = $pStatusMessageContainer;
    $this->response->knr = $this->request->knr;

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array();
  }
} 

class AddDozentRequest
{
  public $isRefresh;
  public $isXsrfOk;
  public $dozId;
  public $knr;
}

class AddDozentResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $statusMessageContainer;
  public $knr;
}