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

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */
class KtoPruef
{
  private static $instance = null;

  
  private static function _getInstance()
  {
    if (!is_null(self::$instance)) {
      return self::$instance;
    }

    switch (KTOPRUEF_TYP) {
      case 'webservice':
        self::$instance = new KtoPruef\WebCheck();
        break;
      case 'local_files':
        self::$instance = new KtoPruef\LocalCheck();
        break;
      default:
        self::$instance = new KtoPruef\NoCheck();
        break;
    }

    return self::$instance;
  }

  
  public static function checkKto($kto, $blz)
  {
    return self::_getInstance()->checkKto($blz, $kto);
  }

  
  public static function checkBLZ($blz)
  {
    return self::_getInstance()->checkBLZ($blz);
  }

  
  public static function getBank4Blz($blz)
  {
    return self::_getInstance()->getBank4Blz($blz);
  }

  
  public static function checkIBAN($iban)
  {
    return self::_getInstance()->checkIBAN($iban);
  }

  
  public static function checkBic($bic)
  {
    $checkBicVereinfacht = false;
    
    
    
    if (defined('KTOPRUEF_AUSLAENDISCHE_BIC_VEREINFACHT') && KTOPRUEF_AUSLAENDISCHE_BIC_VEREINFACHT) {
      $dbwBasysSettings = new DBWorkBASysSettings(1, true);
      $settings = $dbwBasysSettings->getSettings();
      $bundeslandKuerzel = StringOperations::substr($settings->bundesland, 0, 2);
      
      
      $laenderCode = StringOperations::substr($bic, 4, 2);

      $checkBicVereinfacht = !($laenderCode === 'DE' && $bundeslandKuerzel !== 'A-'
                                || $laenderCode === 'AT' && $bundeslandKuerzel === 'A-');
    }

    if ($checkBicVereinfacht) {
      return SimpleBicCheck::check($bic);
    } else {
      return self::_getInstance()->checkBic($bic);
    }
  }

  
  public static function getBank4Bic($bic)
  {
    return self::_getInstance()->getBank4Bic($bic);
  }
}