<?php
require_once 'config/database.php';

function checkTable($pdo, $tableName) {
    try {
        $stmt = $pdo->query("SELECT name FROM sqlite_master WHERE type='table' AND name='$tableName'");
        if ($stmt->fetch()) {
            echo "TABLE:$tableName:EXISTS\n";
        } else {
            echo "TABLE:$tableName:MISSING\n";
        }
    } catch (Exception $e) {
        echo "TABLE:$tableName:ERROR:" . $e->getMessage() . "\n";
    }
}

checkTable($pdo, 'mail_activity');
checkTable($pdo, 'user_progress');

try {
    $users = $pdo->query("SELECT user_id FROM user_progress")->fetchAll(PDO::FETCH_COLUMN);
    echo "USER_PROGRESS_IDS:" . implode(',', $users) . "\n";
} catch (Exception $e) {
    echo "USER_PROGRESS_IDS:ERROR:" . $e->getMessage() . "\n";
}

try {
    $all_users = $pdo->query("SELECT id FROM users")->fetchAll(PDO::FETCH_COLUMN);
    echo "USER_IDS:" . implode(',', $all_users) . "\n";
} catch (Exception $e) {
    echo "USER_IDS:ERROR:" . $e->getMessage() . "\n";
}
?>
