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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\DetailsReiter\Dokumente;

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

  public function action()
  {
    return $this->getResponse();
  }

  protected function getResponse()
  {
    try {
      $this->response->datDoc = $this->getDokumentenListe();
    } catch (\Exception $ex) {
      $this->response->dmzNichtErreichbar = true;
    }
    $this->response->kurs = $this->getKurs($this->getKursId());
    $this->response->uploadAllowed = $this->isUploadAllowed();

    return $this->response;
  }

  private function getDokumentenListe()
  {
    $datDoc = $this->getDatDocObj();

    return \DatDocAPI::getDokumentenListeFromDmz($datDoc);
  }

  protected function getDatDocObj()
  {
    $result = new \Dat_doc();
    $result->knr = $this->getKursId();

    return $result;
  }

  protected function isUploadAllowed(): bool
  {
    return false;
  }
}

class DokumenteResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $datDoc;
  public $kurs;
  public $dmzNichtErreichbar;
  public $uploadAllowed;
}