<?php

declare(strict_types=1);

namespace Plugin\tnt_mcp\src\Mcp\Mode;

/**
 * THE single choke point that decides whether an endpoint may run under the current {@see Mode}.
 * Pure function, no I/O: {@see \Plugin\tnt_mcp\src\Mcp\Server::dispatch()} calls it once per tool
 * call. Do not scatter mode checks anywhere else.
 *
 * Policy:
 * - {@see Mode::Full}    → allow everything.
 * - {@see Mode::Limited} → allow ONLY {@see EndpointClass::Reversible}. Destructive endpoints, and
 *   — fail-safe — any endpoint with no declared class (null), are denied.
 */
final class ModeGuard
{
    /**
     * @param ?EndpointClass $class the endpoint's declared class, or null when it declares none
     *                              (which is denied in limited mode by design).
     */
    public static function permits(Mode $mode, ?EndpointClass $class): bool
    {
        if ($mode === Mode::Full) {
            return true;
        }

        return $class === EndpointClass::Reversible;
    }
}
