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

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

use Kufer\KuferTools\Utils\WssField\WssField;

class WssFieldTextWithMaxLength extends WssField
{
  protected $maxLength;

  
  public function __construct($datamodulColumn, int $maxLength)
  {
    parent::__construct($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;
  }
}