-- Step 1 of Tetris 1v1 multiplayer: room lobby storage
CREATE TABLE IF NOT EXISTS tetris_rooms (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    room_code VARCHAR(6) NOT NULL,
    host_name VARCHAR(24) NOT NULL,
    guest_name VARCHAR(24) DEFAULT NULL,
    status ENUM('waiting', 'ready', 'closed') NOT NULL DEFAULT 'waiting',
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    expires_at TIMESTAMP NULL DEFAULT NULL,
    UNIQUE KEY uniq_room_code (room_code),
    KEY idx_status (status),
    KEY idx_expires_at (expires_at),
    KEY idx_updated_at (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
