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

namespace Kufer\KuferTools\Basis\UseCase;


abstract class UseCase
{
  
  protected $request;

  
  protected $response;

  
  public function __construct($request, $response)
  {
    $this->request = $request;
    $this->initResponse($response);
  }

  
  public function getRequest()
  {
    return $this->request;
  }

  
  abstract public function action();

  abstract public function hasAccess($pToolSectionId = null);

  
  protected function initResponse($response)
  {
    $this->response = $response;
    $this->initResponseBase($response);
  }

  protected function initResponseBase($response)
  {
    $response->sprachSettings = \SettingsFactory::getSettings(\SprachSettingsObject::class);
    $response->datum_akt = \DateTimeOperations::getDateNow();

    $allgSettings = \AllgSettingsAPI::getAllgSettings();
    $response->impressum = $allgSettings->impressum;
    $response->agb = $allgSettings->vhsagb;
    $response->datenschutz = $allgSettings->vhsdatenschutz;

    $toolSettings = \ToolSettingsAPI::getToolSettings(0);
    $response->showToolTipOnError = $toolSettings->showToolTipOnError;

    $version = \Version::getCurrentVersion();
    $response->copyrightYear = \StringOperations::substr($version->versionDate, -4);
    if (PRAESENTATION) {
      $response->copyrightYear = \DateTimeOperations::getYear(\DateTimeOperations::getDateNow());
    }

    $response->statusMeldungen = \Kufer\KuferTools\Utils\StatusMessages\StatusMessageContainer::getSharedInstance();
  }

  
  public function checkLogin()
  {
    return true;
  }

  protected function handleResponseStrategies()
  {
    $rsArray = array_filter($this->getResponseStrategies());
    foreach ($rsArray as $rs) {
      $this->response = $rs->extendResponse($this->response);
    }
  }

  protected function getResponseStrategies()
  {
    return array();
  }
}


class BasisResponse
{
  public $sprachSettings;
  public $datum_akt;
  public $impressum = '';
  public $agb = '';
  public $datenschutz = '';
  public $showToolTipOnError = false;
  public $statusMeldungen;
}