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

use Gestoreasy\Core\Tenant\ConnectionManager;

$tenant = $argv[1] ?? 'default';
putenv("TENANT_ID={$tenant}");

try {
    $pdo = ConnectionManager::forTenant();
    $stmt = $pdo->query('SELECT COUNT(*) AS c FROM audit_logs');
    $row = $stmt->fetch();
    echo json_encode(['tenant'=>$tenant, 'count'=>(int)($row['c'] ?? 0)]);
} catch (Throwable $e) {
    echo json_encode(['error'=>$e->getMessage()]);
    exit(1);
}