<?php
declare(strict_types=1);
require __DIR__ . '/next_plan.php';

$routes = next_read_routes();
if (count($routes) < 10) throw new RuntimeException('Fewer than ten safe candidates');
$seen = [];
foreach ($routes as $route) {
    $key = $route['method'] . ' ' . $route['path'];
    if (isset($seen[$key])) throw new RuntimeException('Duplicate candidate');
    $seen[$key] = true;
    if (!in_array($route['method'], ['GET', 'POST'], true)
        || !preg_match('#^/api/[A-Za-z0-9._/-]+$#', $route['path'])
        || !in_array($route['source_side'], ['ai', 'store'], true)
        || !preg_match('/^[a-z_]+$/', $route['source_table'])
        || !in_array($route['owner_column'], ['USER_ID', 'AI_USER_ID',
            'STAFF_ID', ''], true)
        || !in_array($route['selector'], ['', 'sport_item_id',
            'course_id', 'activity_id'], true)
        || preg_match('#/(submit|add|create|update|delete|sync|suggestion|today)$#i',
            $route['path'])) {
        throw new RuntimeException('Unsafe candidate shape');
    }
}
echo 'next read plan: ' . count($routes) . " candidates green\n";
