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

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

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

  public static function getToolSectionId()
  {
    return 755;
  }

  protected function isUploadAllowed(): bool
  {
    return $this->isRechtAllowed('756.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->typ = 'D_T'; 
    $datDoc->nr = $user->tnr;
    $datDoc->freigabe_tn_tools = true;

    return $datDoc;
  }

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

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

    return $email;
  }

  protected function getDbTypAndId(): array
  {
    return array('T', $this->getUser()->getTnrIdentifier());
  }
}