-- Persistent scoreboard entries for completed Tetris runs.
CREATE TABLE IF NOT EXISTS tetris_scores (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    player_name VARCHAR(48) NOT NULL DEFAULT 'Player',
    score INT UNSIGNED NOT NULL DEFAULT 0,
    lines_cleared INT UNSIGNED NOT NULL DEFAULT 0,
    level INT UNSIGNED NOT NULL DEFAULT 1,
    pieces_placed INT UNSIGNED NOT NULL DEFAULT 0,
    duration_seconds INT UNSIGNED NOT NULL DEFAULT 0,
    mode ENUM('solo', 'multiplayer') NOT NULL DEFAULT 'solo',
    room_code VARCHAR(8) NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_tetris_scores_rank (score, lines_cleared, level, duration_seconds),
    KEY idx_tetris_scores_created (created_at),
    KEY idx_tetris_scores_mode (mode)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
