<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\AgeVerification;

use Symfony\Component\HttpFoundation\Request;

final readonly class RobotRequestDetector
{
    private const string ROBOT_PATTERN = '/(?:bot|crawler|spider|slurp|bingpreview|facebookexternalhit|facebot|google-inspectiontool|ia_archiver|lighthouse|mediapartners-google|pinterest|preview|telegrambot|twitterbot|whatsapp|yandex|yeti)/i';

    public function isRobot(Request $request): bool
    {
        $userAgent = mb_trim((string) $request->headers->get('User-Agent'));

        return '' !== $userAgent && 1 === preg_match(self::ROBOT_PATTERN, $userAgent);
    }
}
