<?php
require __DIR__ . '/../bootstrap.php';

use Gestoreasy\Core\Tenant\TenantAdmin;

try {
    $tenants = TenantAdmin::listTenants();
    $out = [];
    foreach ($tenants as $t) {
        try {
            $res = TenantAdmin::runMigrations($t);
            $out[] = [ 'tenant' => $t, 'ok' => true, 'result' => $res ];
        } catch (\Throwable $e) {
            $out[] = [ 'tenant' => $t, 'ok' => false, 'error' => $e->getMessage() ];
        }
    }
    echo json_encode([ 'ok' => true, 'data' => $out ], JSON_UNESCAPED_UNICODE) . "\n";
} catch (\Throwable $e) {
    echo json_encode([ 'ok' => false, 'error' => $e->getMessage() ], JSON_UNESCAPED_UNICODE) . "\n";
}