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


// Test if email_queue table exists
$result = $conn->query("SHOW TABLES LIKE 'email_queue'");
if ($result->num_rows > 0) {
    echo "✓ email_queue table exists\n";
} else {
    echo "✗ email_queue table NOT found - creating it...\n";
    
    // Create the table
    $sql = "CREATE TABLE IF NOT EXISTS email_queue (
        id INT AUTO_INCREMENT PRIMARY KEY,
        consultation_id INT,
        recipient_email VARCHAR(255) NOT NULL,
        subject VARCHAR(500),
        body LONGTEXT,
        email_type VARCHAR(50),
        status VARCHAR(20) DEFAULT 'pending',
        attempts INT DEFAULT 0,
        last_attempt TIMESTAMP,
        sent_at TIMESTAMP,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )";
    
    if ($conn->query($sql)) {
        echo "✓ email_queue table created successfully!\n";
    } else {
        echo "✗ Error creating table: " . $conn->error . "\n";
    }
}

// List all tables
echo "\nAll tables:\n";
$result = $conn->query("SHOW TABLES");
while($row = $result->fetch_row()) {
    echo "  - " . $row[0] . "\n";
}

$conn->close();
?>
