<?php
require_once 'config.php';
require_once 'includes/db.php';

echo "Checking Database Stats...\n";

$counts = $pdo->query("SELECT user_id, COUNT(*) as cnt FROM videos GROUP BY user_id")->fetchAll(PDO::FETCH_ASSOC);
print_r($counts);

echo "\nChecking Users with API Keys...\n";
$users = $pdo->query("SELECT id, email, api_key FROM users")->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $u) {
    $keyLen = strlen($u['api_key'] ?? '');
    $keyPreview = $keyLen > 4 ? substr($u['api_key'], 0, 4) . '...' : $u['api_key'];
    echo "ID: {$u['id']} | Email: {$u['email']} | API Key: [$keyPreview] (Len: $keyLen)\n";
}

echo "\nGlobal SONICPESA_API_TOKEN: " . (defined('SONICPESA_API_TOKEN') ? SONICPESA_API_TOKEN : 'NOT DEFINED') . "\n";
?>

