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

    $laengeKtoNr = strlen((string)$ktoNr * 1);

    $result = false;

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

    return $result;
  }

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

    return Pruefziffer_52::check($pKtoNr, $pBlz, $gewichtung);
  }

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

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