<?php

declare(strict_types=1);

namespace CpCreation\AltchaBundle\Scope;

final class ScopeName
{
    private const PATTERN = '/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/D';

    public static function assertValid(string $scope): void
    {
        if (2 > strlen($scope) || 64 < strlen($scope) || 1 !== preg_match(self::PATTERN, $scope)) {
            throw new \InvalidArgumentException(sprintf('Invalid ALTCHA scope "%s".', $scope));
        }
    }
}
