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

namespace Kufer\KuferTools\Dozent\Anwesenheiten\Feedback;

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

class KursTageFeedbackFormularUseCase extends \Kufer\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\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\KuferTools\Basis\KursDetails\Feedback\FeedbackFormularResponse
{
  public $ktId;
}

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