<?php
/** Lightweight production QA checks that do not mutate data. */
declare(strict_types=1);
define('BASE_PATH', dirname(__DIR__));
require_once BASE_PATH . '/src/config.php';
$errors = [];
$warnings = [];
try { $pdo = db(); $pdo->query('SELECT 1'); } catch (Throwable $e) { $errors[] = 'DB connection failed: ' . $e->getMessage(); }
foreach (['bot_user_states','telegram_update_queue','jobs','payment_idempotency','referral_rewards','resellers'] as $t) {
    try { $st = $pdo->prepare('SHOW TABLES LIKE ?'); $st->execute([$t]); if (!$st->fetchColumn()) $errors[] = "Missing table: {$t}"; } catch (Throwable $e) { $errors[] = "Table check failed {$t}: " . $e->getMessage(); }
}
foreach (['BOT_TOKEN','ADMIN_IDS','DB_HOST','DB_NAME','DB_USER'] as $c) {
    if (!defined($c) || trim((string)constant($c)) === '') $warnings[] = "Empty config: {$c}";
}
echo json_encode(['ok'=>empty($errors), 'errors'=>$errors, 'warnings'=>$warnings], JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . "\n";
exit(empty($errors) ? 0 : 1);
