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

try {
    $pdoconn = db();
    $pdoconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "CREATE TABLE IF NOT EXISTS meetings (
        id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        bni_group_id INT(11) UNSIGNED NOT NULL,
        meeting_datetime DATETIME NOT NULL,
        meeting_key VARCHAR(255) NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        UNIQUE KEY meeting_key (meeting_key),
        FOREIGN KEY (bni_group_id) REFERENCES bni_groups(id) ON DELETE CASCADE
    )";

    $pdoconn->exec($sql);
    echo "Table 'meetings' created successfully." . PHP_EOL;
} catch (PDOException $e) {
    echo "Error creating table: " . $e->getMessage() . PHP_EOL;
    exit(1);
}
