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

namespace Kufer\KuferTools\Veranstalter\ChooseVeranstalter;


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

  public function hasAccess($pToolSectionId = null)
  {
    if (!\is_numeric($this->request->num)) {
      return false;
    }
    if (!\is_numeric($this->request->requestedToolId) && $this->request->requestedToolId !== '') {
      return false;
    }

    $benutzerGruppen = \SessionOperations::getBenutzerGruppenKuerzel();
    if (!\in_array(KURZ_VERANSTALTER, $benutzerGruppen)) {
      return false;
    }

    return true;
  }

  public function action()
  {
    $this->handleResponseStrategies();
    $response = $this->getResponse();

    \Kufer\KuferTools\Veranstalter\Utils\VeranstalterUtils::setVeranstalterDnr($this->request->num);

    return $response;
  }

  private function getResponse(): ChooseVeranstalterResponse
  {
    $this->response->requestedToolId = $this->request->requestedToolId;

    return $this->response;
  }
}

class ChooseVeranstalterRequest
{
  public $num;
  public $requestedToolId;
}

class ChooseVeranstalterResponse extends \Kufer\KuferTools\Basis\UseCase\BasisResponse
{
  public $num;
  public $requestedToolId;
}