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

namespace Kufer\Web\Classes\Dbfilter;

use Kufer\Web\Classes\Identifier\Identifier;


class KursBetreuerSQLFilter extends BasicSQLFilter
{
  protected function __construct()
  {
    parent::__construct();

    $this->registerDb('Id', 'id', static::TYPE_INTEGER);
    $this->registerDb('KursId', 'knr', static::TYPE_STRING);
    $this->registerDb('PersonType', 'typ', static::TYPE_STRING);
    $this->registerDb('PersonId', 'nr', static::TYPE_IDENTIFIER_NO_GUID);
  }

  public function getTablePraeffix(): string
  {
    return 'kursbetreuer';
  }

  public function equalsId($id): IFilter
  {
    $this->applyFilterCurrent(
      static::FILTER_OPTION_ID,
      SQLFilterUtils::filterEqualsIdInt('id', $id)
    );

    return $this;
  }

  public function equalsDozent(Identifier $dozId): KursBetreuerSQLFilter
  {
    $this->all(static function(KursBetreuerSQLFilter $filter) use ($dozId): void {
      $filter->equalsPersonId($dozId);
      $filter->equalsPersonType('D');
    });

    return $this;
  }
}