<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Validation\KtoPruef\Classes;


class WebCheck implements KtoPruefInterface
{
  private $service;

  public function __construct()
  {
    $this->service = new \Kufer\Web\Classes\WebService\WebService();
  }

  public function checkKto($blz, $kto)
  {
    $result = $this->service->doRequest('dta/check', array('blz' => $blz, 'kto' => $kto), 'POST');
    if ($result && $result['result'] == 'true') {
      return true;
    } else {
      return $result['reason'] == 'blz_is_incorrect';
    }
  }

  public function checkBLZ($blz)
  {
    $result = $this->service->doRequest('dta/info', array('blz' => $blz), 'POST');
    if ($result && $result['result'] == 'true') {
      return true;
    } else {
      return false;
    }
  }

  public function getBank4Blz($blz)
  {
    $result = $this->service->doRequest('dta/info', array('blz' => $blz), 'POST');
    if ($result && $result['result'] == 'true') {
      return $result['info'];
    } else {
      return false;
    }
  }

  public function checkIBAN($iban)
  {
    $result = $this->service->doRequest('sepa/check', array('iban' => $iban), 'POST');
    if ($result && $result['result'] == 'true') {
      return true;
    } else {
      return false;
    }
  }

  public function checkBic($bic)
  {
    $result = $this->service->doRequest('sepa/info', array('bic' => $bic), 'POST');
    if ($result && $result['result'] == 'true') {
      return true;
    } else {
      return false;
    }
  }

  public function getBank4Bic($bic)
  {
    $result = $this->service->doRequest('sepa/info', array('bic' => $bic), 'POST');
    if ($result && $result['result'] == 'true') {
      return $result['info'];
    } else {
      return false;
    }
  }
}