<?php
require_once __DIR__ . '/../src/Utils/Env.php';
require_once __DIR__ . '/../src/Config/Database.php';

use App\Utils\Env;
use App\Config\Database;

Env::load(__DIR__ . '/../../.env');
$db = Database::getInstance()->getConnection();

echo "<pre>\n";

try {
    $db->exec("
        CREATE TABLE IF NOT EXISTS blocked_users (
            id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            blocker_id BIGINT UNSIGNED NOT NULL,
            blocked_id BIGINT UNSIGNED NOT NULL,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            UNIQUE KEY unique_block (blocker_id, blocked_id),
            INDEX(blocker_id, created_at),
            INDEX(blocked_id, created_at),
            CONSTRAINT fk_blocked_users_blocker_id FOREIGN KEY (blocker_id) REFERENCES users(id) ON DELETE CASCADE,
            CONSTRAINT fk_blocked_users_blocked_id FOREIGN KEY (blocked_id) REFERENCES users(id) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ");
    echo "Ensured blocked_users table exists\n";
} catch (PDOException $e) {
    echo "blocked_users: " . $e->getMessage() . "\n";
}

echo "\nDone.\n</pre>";

