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

namespace Kufer\Web\KuferTools\Utils\Spezial;

use Kufer\Web\Classes\Dbfilter\KennzeichenAdSQLFilter;
use Kufer\Web\Classes\Identifier\Identifier;

class BadMergentheimFABIUtils
{
  public static function isFirmaEligibleForFoerderung(Identifier $firmaId): bool
  {
    if (\DBWorkBASysSettings::isBadMergentheimFabi()) {
      $dbwKennAd = \DBWorkKennzAd::getDefaultInstance();

      $origFilter = KennzeichenAdSQLFilter::create();
      $origFilter->equalsId($firmaId->getId());
      $origFilter->equalsTyp('T');

      $filter = clone $origFilter;
      $filter->any(function(KennzeichenAdSQLFilter $filter): KennzeichenAdSQLFilter {
        
        $filter->equalsKennz(1);

        return $filter;
      });
      if ($dbwKennAd->existsByFilter($filter)) {
        return false;
      }

      $filter = $origFilter;
      $filter->any(function(KennzeichenAdSQLFilter $filter): KennzeichenAdSQLFilter {
        
        
        $filter->equalsKennz(2);
        $filter->equalsKennz(3);

        return $filter;
      });

      return $dbwKennAd->existsByFilter($filter);
    }

    return false;
  }
}