<?php

declare(strict_types=1);

namespace FleekDash\Routes;

/**
 * Menu endpoints are read-heavy (sidebar + polling + MessageBus). Exempt GETs from
 * the global per-route transient limit to avoid 429 while keeping writes limited.
 */
final class RestRateLimitMenuExemption
{
    public static function isExempt(\WP_REST_Request $request, string $routePath): bool
    {
        $exempt = $routePath !== ''
            && $request->get_method() === 'GET'
            && strpos($routePath, 'v1/menu') !== false;
        if (!$exempt) {
            return false;
        }
        $blocked = [
            'menu/refresh',
            'menu/cache-cleared',
            'menu/invalidate',
            'menu/overrides',
        ];
        foreach ($blocked as $needle) {
            if (strpos($routePath, $needle) !== false) {
                return false;
            }
        }
        return true;
    }
}
