<?php
// Simple static test to verify that subusersRoute links GET /subusers to the SUBUSERS_LIST node via definePermission
if (!defined('WD')) {
    define('WD', dirname(__DIR__, 2));
}

function ok($message): void { echo "\n\033[32m✔ $message\033[0m\n"; }
function fail($message): void { echo "\n\033[31m✖ $message\033[0m\n"; exit(1); }

$routeFile = WD . '/routes/subusersRoute.php';
if (!file_exists($routeFile)) {
    fail('subusersRoute.php not found');
}

$code = file_get_contents($routeFile);
if ($code === false) {
    fail('Unable to read subusersRoute.php');
}

// Normalize whitespace to avoid formatting issues
$normalized = preg_replace('/\s+/', ' ', $code);

// Look for the specific definePermission linkage to SUBUSERS_LIST
$needle = "definePermission('list_own_subusers', subusers_permission_node_key::SUBUSERS_LIST)";
if (strpos($normalized, $needle) !== false) {
    ok('Subusers route links list permission to SUBUSERS_LIST node');
} else {
    fail('Expected permission linkage to SUBUSERS_LIST not found in subusersRoute');
}

echo "\nSubusersRoutePermissionLinkTest completed.\n";
