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

namespace Kufer\Web\KuferTools\Utils\WssField\Basis;

use Kufer\Web\KuferTools\Basis\UseCaseBuilder\ToolSection;

class WssFieldTextWithMaxLength extends \Kufer\Web\KuferTools\Utils\WssField\WssField
{
  protected $maxLength;

  
  public function __construct(ToolSection $toolSection, \ToolSettings $toolSettings, $datamodulColumn, int $maxLength)
  {
    parent::__construct($toolSection, $toolSettings, $datamodulColumn);
    $this->maxLength = $maxLength;
  }

  public function getDefaultMaxLength(): ?int
  {
    return $this->maxLength;
  }

  public function isValid($value, bool $checkPflichtfelder = true): bool
  {
    if (!parent::isValid($value, $checkPflichtfelder)) {
      return false;
    }

    if (\StringOperations::strlen($value) > $this->getDmColumnMitDefaultBeruecksichtigt()->maxlength) {
      return false;
    }

    return true;
  }
}