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

namespace Kufer\Web\KuferTools\Utils\FilterSettings\Dozenten;

use Kufer\KuferTools\Veranstalter\Utils\VeranstalterUtils;
use Kufer\Web\KuferTools\Utils\FilterSettings\FilterSettingsCompositor;
use Kufer\Web\KuferTools\Utils\FilterSettings\IFilterSettings;

class DozentenFilterSettingsHelper
{
  private function __construct()
  {
  }

  public static function createBasicFilterSettings(): IFilterSettings
  {
    return new FilterSettingsCompositor(); 
  }

  protected static function createNichtVerstorbenNichtInaktivFilterSettings(bool $inaktiveDozentenAusblenden, bool $verstorbeneDozentenAusblenden): IFilterSettings
  {
    $result = array();
    if ($inaktiveDozentenAusblenden) {
      $result[] = new NotInaktiveDozentenFilterSettings();
    }
    if ($verstorbeneDozentenAusblenden) {
      $result[] = new NotVerstorbeneDozentenFilterSettings();
    }

    return new FilterSettingsCompositor(...$result);
  }

  protected static function createDozentenTypFilterSettings(string $dozTyp): IFilterSettings
  {
    if ($dozTyp === '') {
      return new FilterSettingsCompositor();
    } else {
      $dozTypAry = \ArrayOperations::replace(\StringOperations::str_split($dozTyp), '-', '');

      return new DozentenTypFilterSettings($dozTypAry);
    }
  }

  protected static function createDozentenMitKennzeichenFilterSettings(string $nurDozentenMitKennzeichen): IFilterSettings
  {
    if ($nurDozentenMitKennzeichen === '-') {
      return new FilterSettingsCompositor();
    }

    return new KennzeichenFilterSettings($nurDozentenMitKennzeichen);
  }

  public static function createUebersichtBasicFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    return new FilterSettingsCompositor(
      static::createBasicFilterSettings(),
      static::createNichtVerstorbenNichtInaktivFilterSettings($toolSettings->inaktiveDozentenAusblenden, $toolSettings->verstorbeneDozentenAusblenden),
      static::createDozentenTypFilterSettings($toolSettings->doztyp),
      static::createDozentenMitKennzeichenFilterSettings($toolSettings->nurDozentenMitKennzeichen ?? ''),
      new NotEquals0FilterSettings()
    );
  }

  public static function createMitarbeiterUebersichtFilterSettings(\ToolSettings $toolSettings, \Benutzer $user): IFilterSettings
  {
    $additionalSettings = array();
    if ($toolSettings->useBereichsRechte) {
      $additionalSettings[] = new BereichsrechteFilterSettings($user);
    }

    return new FilterSettingsCompositor(
      static::createUebersichtBasicFilterSettings($toolSettings),
      ...$additionalSettings
    );
  }

  public static function createVeranstalterUebersichtFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    $additionalSettings = array();
    if (\DBWorkBASysSettings::isSalzburgBildungswerk()) {
      
      
      $mainVeranstalter = VeranstalterUtils::getVeranstalterDozent();
      $additionalSettings[] = new EinsatzbezirkFilterSettings($mainVeranstalter->bezirk);
    }

    return new FilterSettingsCompositor(
      static::createUebersichtBasicFilterSettings($toolSettings),
      new NotTypFilterSettings(VeranstalterUtils::getTypenNichtDozent()),
      ...$additionalSettings
    );
  }

  protected static function createBasicKursvorschlagFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    return static::createBasicFilterSettings();
  }

  public static function createVeranstalterKursvorschlagFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    $additionalSettings = array();
    if (\DBWorkBASysSettings::isSalzburgBildungswerk()) {
      $additionalSettings[] = new DozentenTypFilterSettings(array('D', VeranstalterUtils::TYPE_DOZENT_LEITER_UND_DOZENT));
    } else {
      $additionalSettings[] = new NotTypFilterSettings(VeranstalterUtils::getTypenNichtDozent());
    }

    return new FilterSettingsCompositor(
      static::createBasicKursvorschlagFilterSettings($toolSettings),
      ...$additionalSettings
    );
  }

  protected static function createKooperationspartnerKursvorschlagBasicFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    return static::createBasicFilterSettings();
  }

  public static function createVeranstalterKooperationspartnerKursvorschlagFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    return new FilterSettingsCompositor(
      static::createKooperationspartnerKursvorschlagBasicFilterSettings($toolSettings),
      new DozentenTypFilterSettings(VeranstalterUtils::getTypenKooperationspartner())
    );
  }

  public static function createVeranstalterLeiterUndMitarbeiterUebersichtFilterSettings(\ToolSettings $toolSettings): IFilterSettings
  {
    $additionalSettings = array();
    if (\DBWorkBASysSettings::isSalzburgBildungswerk()) {
      $additionalSettings[] = new MitarbeiterOderVeranstalterFilterSettings();
    }

    return new FilterSettingsCompositor(
      static::createBasicFilterSettings(),
      ...$additionalSettings
    );
  }

  public static function createFirmaAusbilderDozentenauswahlFilterSettings(\ToolSettings $toolSettings, \Benutzer $user): IFilterSettings
  {
    return new FilterSettingsCompositor(
      static::createBasicFilterSettings(),
      new HasBeziehungWithFirmaFilterSettings($user)
    );
  }
}