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

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

use Kufer\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\KuferTools\Basis\UseCase\BasisResponse
{
  
  public $kurs;
  
  public $belegungen;
  
  public $referer;
  
  public $refererLabel;
  
  public $shouldWrite;
}