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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\TnZertifikat;

use Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseMitRahmen;

abstract class TnZertifikatUseCase extends BasicTnZertifikatUseCase
{
  public function __construct($request, $response = null)
  {
    parent::__construct($request, $response ?? new TnZertifikatResponse());
  }

  public function action()
  {
    parent::action();

    $belegungsHelper = $this->getBelegungsHelper($this->response->kurs);
    $this->response->belegungen = $belegungsHelper->getDatamoduleOhneFilter();

    $this->response->referer = $this->getBackLink();
    $this->response->refererLabel = $this->getBackButtonLabel();

    $this->response->shouldWrite = (\SessionOperations::isDmzBetrieb() || !\DBConnectionInfo::getInstance()->db_replikat) && $this->toolSettings->tnZertifikatSpeichern;

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array_merge(
      parent::getResponseStrategies(),
      array(
        new ResponseMitRahmen($this)
      )
    );
  }

  protected function getBackLink(): string
  {
    return 'index.php?tool_id=' . static::getToolId() . '&action=kursdetails&knr=' . $this->request->knr;
  }

  protected function getBackButtonLabel(): string
  {
    return 'Zurück';
  }
}

class TnZertifikatRequest
{
  public $knr;
}

class TnZertifikatResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  
  public $kurs;
  
  public $belegungen;
  
  public $referer;
  
  public $refererLabel;
  
  public $shouldWrite;
}