<?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_B2 implements IPruefziffer
{
  public static function check($pKtoNr, $pBlz, $pGewichtung = array(), $pPruefZifferStelle = 9)
  {
    $ktoNr = \str_pad($pKtoNr, 10, '0', STR_PAD_LEFT);

    if ($ktoNr[0] <= 7) {
      $result = self::variante1($ktoNr, $pPruefZifferStelle);
    } else {
      $result = self::variante2($ktoNr, $pPruefZifferStelle);
    }

    return $result;
  }

  private static function variante1($pKtoNr, $pPruefZifferStelle)
  {
    $gewichtung = array(0, 2, 3, 4, 5, 6, 7, 8, 9, 2);

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

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

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