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

namespace Kufer\Web\KuferTools\Dozent\Anwesenheiten\Feedback;

use Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase;
use Kufer\Web\KuferTools\Dozent\Anwesenheiten\Utils\KurstageUtils;

class KursTageFeedbackFormularUseCase extends \Kufer\Web\KuferTools\Basis\KursDetails\Feedback\FeedbackFormularUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new KtFeedbackFormularResponse());
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_ANWESENHEIT_DOZ;
  }

  public static function getToolSectionId()
  {
    return 291;
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!ToolUseCase::hasAccess()) {
      return false;
    }
    if (!KurstageUtils::hasAccessToKurstag($this->request->ktId, $this->toolSettings)) {
      return false;
    }

    return true;
  }

  public function action()
  {
    $kursTage = $this->getKurstag();

    return $this->getResponse($kursTage->kurs);
  }

  protected function getKurstag()
  {
    $dbwKT = KurstageUtils::getDbwKursTage($this->toolSettings);

    return $dbwKT->getKurstag($this->request->ktId);
  }

  protected function getResponse($kurs)
  {
    parent::getResponse($kurs);
    $this->response->ktId = $this->request->ktId;

    return $this->response;
  }

  protected function getResponseStrategies()
  {
    return array(
        new \Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseMitRahmen($this)
    );
  }

  protected function getAction(): string
  {
    return 'kurstagUebersicht&datum=' . $this->getKurstag()->datum;
  }

  protected function getKursnummer()
  {
    return $this->getKurstag()->knr;
  }

  protected function getRequestedId()
  {
    return $this->getKurstag()->knr;
  }

  protected function getXsrfRequestedId()
  {
    return $this->getKurstag()->id;
  }
}

class KtFeedbackFormularRequest extends \Kufer\Web\KuferTools\Basis\KursDetails\Feedback\FeedbackFormularResponse
{
  public $knr;
  public $ktId;
}

class KtFeedbackFormularResponse extends \Kufer\Web\KuferTools\Basis\KursDetails\Feedback\FeedbackFormularResponse
{
  public $ktId;
}