CREATE TABLE IF NOT EXISTS mines_pool (
    id TINYINT UNSIGNED NOT NULL PRIMARY KEY DEFAULT 1,
    balance DECIMAL(18,2) NOT NULL DEFAULT 0.00,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS mines_games (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id INT(11) NOT NULL,
    bet DECIMAL(18,2) NOT NULL,
    mine_count TINYINT UNSIGNED NOT NULL DEFAULT 3,
    rows_c TINYINT UNSIGNED NOT NULL DEFAULT 5,
    cols_c TINYINT UNSIGNED NOT NULL DEFAULT 5,
    safe_clicks TINYINT UNSIGNED NOT NULL DEFAULT 0,
    is_over TINYINT(1) NOT NULL DEFAULT 0,
    is_win TINYINT(1) DEFAULT NULL,
    payout DECIMAL(18,2) NOT NULL DEFAULT 0.00,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    ended_at DATETIME DEFAULT NULL,
    INDEX idx_user (user_id),
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
