<?php
require_once __DIR__ . '/config/database.php';
function sendError($msg, $code) { echo "Error: $msg ($code)\n"; }

$db = getDb();
$tables = ['addresses', 'wishlist', 'orders', 'order_items'];
$report = [];

foreach ($tables as $table) {
    $result = $db->query("SHOW COLUMNS FROM $table");
    if ($result) {
        $cols = [];
        while ($row = $result->fetch_assoc()) {
            $cols[$row['Field']] = $row['Type'];
        }
        $report[$table] = $cols;
    } else {
        $report[$table] = ['error' => $db->error];
    }
}
file_put_contents(__DIR__ . '/db_report.json', json_encode($report, JSON_PRETTY_PRINT));
echo "Report written to db_report.json\n";
