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

$routes = batch_smoke_routes();
if (count($routes) < 20) throw new RuntimeException('Need at least 20 candidates');
$keys = [];
foreach ($routes as $route) {
    $key = $route['method'] . ' ' . $route['path'];
    if (isset($keys[$key])) throw new RuntimeException('Duplicate route');
    $keys[$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'])
        || !is_bool($route['owned']) || !is_array($route['params'])) {
        throw new RuntimeException('Route safety shape');
    }
    if (preg_match('#/(add|submit|update|delete|sync|create|qrcode|suggestion|status)$#i',
        $route['path'])) {
        throw new RuntimeException('Potential write or external route');
    }
}
echo 'batch smoke route plan: ' . count($routes) . " candidates green\n";
