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

    if (substr($ktoNr, 2, 2) == '99') {
      $gewichtung = array(0, 2, 3, 4, 5, 6, 7, 8, 0, 0);

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

    $result = self::methodeA($ktoNr);
    if (!$result) {
      $result = self::methodeB($ktoNr);
    }
    if (!$result) {
      $result = self::methodeC($ktoNr);
    }

    return $result;
  }

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

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

  private static function methodeB($pKtoNr)
  {
    $gewichtung = array(0, 2, 3, 4, 5, 6, 0, 0, 0, 0);

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

  private static function methodeC($pKtoNr)
  {
    $gewichtung = array(0, 2, 3, 4, 5, 6, 0, 0, 0, 0);

    $strZahl = strrev($pKtoNr);

    $ary = PruefZiffHelpers::gewichten($strZahl, $gewichtung);

    $rest = array_sum($ary) % 7;

    $result = (7 - $rest) % 7;

    return ($result == $pKtoNr[9]);
  }
}