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

namespace Kufer\KuferTools\Basis\Dokumente\DokumenteUpload;

abstract class DokumenteUploadFormularUseCase extends \Kufer\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\KuferTools\Utils\ResponseStrategies\ResponseMenuBar($this),
        new \Kufer\KuferTools\Utils\ResponseStrategies\ResponseUser($this)
    );
  }
}

class DokumenteUploadFormularRequest
{
}

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