<?php
require_once 'config.php';

try {
    $pdo->exec("CREATE TABLE IF NOT EXISTS endpoints (
        id INT AUTO_INCREMENT PRIMARY KEY,
        message_data VARCHAR(255) NOT NULL,
        status TINYINT NOT NULL DEFAULT 1 COMMENT '1=Active, 0=Inactive',
        created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    )");

    $pdo->exec("CREATE TABLE IF NOT EXISTS endpoint_state (
        owner_id INT NOT NULL,
        owner_type VARCHAR(10) NOT NULL,
        last_endpoint_index INT DEFAULT -1,
        PRIMARY KEY (owner_id, owner_type)
    )");

    echo "Tables 'endpoints' and 'endpoint_state' created/verified successfully.";
} catch (PDOException $e) {
    echo "Error creating table: " . $e->getMessage();
}
?>