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

namespace Kufer\KuferTools\Dozent\Dokumente\DokumenteUpload;

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

  public static function getToolSectionId()
  {
    return 745;
  }

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

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

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

  protected function getDatDocObj()
  {
    $datDoc = parent::getDatDocObj();
    $user = $this->getUser();
    $datDoc->nr = $user->dnr;
    $datDoc->freigabe_doz_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;
  }
}