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

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */
class Pruefziffer_B1 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $ktoNr = \str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);

    $result = self::variante1($ktoNr, $pPruefZifferStelle);
    if (!$result) {
      $result = self::variante2($ktoNr, $pPruefZifferStelle);
    }
    if (!$result) {
      $result = self::variante3($ktoNr, $pPruefZifferStelle);
    }

    return $result;
  }

  private static function variante1($pKtoNr, $pPruefZifferStelle)
  {
    $gewichtung = array(0, 7, 3, 1, 7, 3, 1, 7, 3, 1);

    return Pruefziffer_05::check($pKtoNr, null, $gewichtung, $pPruefZifferStelle);
  }

  private static function variante2($pKtoNr, $pPruefZifferStelle)
  {
    $gewichtung = array(0, 3, 7, 1, 3, 7, 1, 3, 7, 1);

    return Pruefziffer_01::check($pKtoNr, null, $gewichtung, $pPruefZifferStelle);
  }

  private static function variante3($pKtoNr, $pPruefZifferStelle)
  {
    $gewichtung = array(0, 2, 1, 2, 1, 2, 1, 2, 1, 2);

    return Pruefziffer_00::check($pKtoNr, null, $gewichtung, $pPruefZifferStelle);
  }
}