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

namespace Kufer\Web\KuferTools\Basis\Dokumente\DokumenteUpload;

abstract class DokumenteUploadFormularUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request, $response = null)
  {
    parent::__construct($request, \is_null($response) ? new DokumenteUploadFormularResponse() : $response);
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess()) {
      return false;
    }

    if (!$this->isUploadAllowed()) {
      return false;
    }

    return true;
  }

  abstract protected function isUploadAllowed(): bool;

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

  protected function getResponse()
  {
    $this->handleResponseStrategies();
    $this->response->externeDokumenteKategorien = $this->getExterneDokumenteKategorien();
    $this->response->adminUserUploadAllowed = !$this->isAdminUserUploadNotAllowed();

    return $this->response;
  }

  private function getExterneDokumenteKategorien()
  {
    $dbw = new \DBWorkHLExterneDokumenteKategorien(1, true);

    return $dbw->getAll();
  }

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

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

class DokumenteUploadFormularRequest
{
}

class DokumenteUploadFormularResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $user;
  public $menuPunkte = array();
  public $externeDokumenteKategorien = array();
  public $adminUserUploadAllowed;
}