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

namespace Kufer\Web\KuferTools\Basis\TeilnehmerInfo\Detailsreiter\Bankverbindungen\Bankdaten;

abstract class BankdatenUseCase extends \Kufer\KuferTools\Basis\UseCase\EinzelTeilnehmerUseCase
{
  public function __construct($request, $response = null)
  {
    parent::__construct($request, $response ?? new BankdatenResponse());
  }

  public function action()
  {
    $bankdaten = $this->getStammBv4Ajax($this->request->stammBvId);

    return $this->getResponse($bankdaten);
  }

  
  private function getStammBv4Ajax($pId)
  {
    $dbwStammBv = new \DBWorkStammBv();
    $tnr = $this->request->tnr;
    $dbwStammBv->isTnOwner($pId, $tnr);
    $stammBv = $dbwStammBv->getOne($pId);

    return \JsonOperations::encodeBase64($stammBv);
  }

  protected function getResponse($bankdaten)
  {
    $this->response->bankdaten = $bankdaten;

    return $this->response;
  }
}

class BankdatenRequest
{
  public $stammBvId;
  public $tnr;
  public $tguid;
}

class BankdatenResponse extends \Kufer\KuferTools\Basis\UseCase\ToolResponse
{
  public $bankdaten;
}