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

namespace Kufer\KuferTools\Veranstalter\Dokumente\DokumenteUpload;

class DokumenteUploadUseCase extends \Kufer\KuferTools\Basis\Dokumente\DokumenteUpload\DokumenteUploadUseCase
{
  public static function getToolId()
  {
    return \ToolsAPI::TOOL_DOKUMENTE_VA;
  }

  public static function getToolSectionId()
  {
    return 694;
  }

  protected function isUploadAllowed(): bool
  {
    return $this->isRechtAllowed('693.0.1');
  }

  protected function shouldSendInfoAnEinrichtung(): bool
  {
    return $this->toolSettings->sendInfoMailAnEinrichtung;
  }

  protected function shouldSendUploadInfoMailMitAnhang(): bool
  {
    return $this->toolSettings->anhangBeiInfoMailAnEinrichtung;
  }

  private function getVeranstalterDnr()
  {
    return \Kufer\KuferTools\Veranstalter\Utils\VeranstalterUtils::getVeranstalterDnr();
  }

  protected function getDatDocObj()
  {
    $datDoc = parent::getDatDocObj();
    $datDoc->nr = $this->getVeranstalterDnr();
    $datDoc->freigabe_veran_tools = true;

    return $datDoc;
  }

  protected function createInfoMailAnEinrichtungView($viewModel): \Kufer\KuferTools\Basis\Dokumente\DokumenteUpload\InfoMailAnEinrichtungView
  {
    return new InfoMailAnEinrichtungView($viewModel);
  }

  protected function getEMailAddressFromToolSettings(): ?string
  {
    $email = $this->toolSettings->emailAnEinrichtungCustomForUpload ?? '';
    if (trim($email) === '') {
      return null;
    }

    return $email;
  }
}