<?php

declare(strict_types=1);

namespace App\Administration\Domain\Exception;

use DomainException;

use function mb_substr;
use function preg_replace;
use function sprintf;

final class CalendrierLabelInvalideException extends DomainException
{
    public static function pourLongueur(string $label, int $min, int $max): self
    {
        $sanitized = preg_replace('/[\x00-\x1f\x7f]/u', '', mb_substr($label, 0, 50));

        return new self(sprintf(
            'Le libellé "%s" doit contenir entre %d et %d caractères.',
            $sanitized,
            $min,
            $max,
        ));
    }
}
