<?php

namespace NoahVet\Reef\Domain\Comparator;

class PrivilegedCodeComparator implements PrivilegedCodeComparatorInterface
{
    #[\Override]
    public function shouldNotContainABlacklistedWord(
        string $privilegedCode,
    ): bool {
        $privilegedCodePrefix = \substr($privilegedCode, 0, 3);

        foreach (self::BLACKLIST as $blackListedElement) {
            if (\str_contains($privilegedCodePrefix, $blackListedElement)) {
                return false;
            }
        }

        return true;
    }

    #[\Override]
    public function shouldNotContainTheSameLetterTwiceConsecutively(
        string $privilegedCode,
    ): bool {
        $privilegedCodePrefix = \substr($privilegedCode, 0, 3);
        if (
            $privilegedCodePrefix[1] == $privilegedCodePrefix[0]
            || $privilegedCodePrefix[1] == $privilegedCodePrefix[2]
        ) {
            return false;
        }

        return true;
    }
}
