CREATE TABLE `blackjack_games` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int NOT NULL,

    `active_key` varchar(64) DEFAULT NULL,

    `wager` bigint unsigned NOT NULL DEFAULT 0,

    `status` enum('playing','settled') NOT NULL DEFAULT 'playing',

    `shoe` text NOT NULL,
    `shoe_pos` int unsigned NOT NULL DEFAULT 0,

    `player_cards` text NOT NULL,
    `dealer_cards` text NOT NULL,

    `player_points` tinyint unsigned NOT NULL DEFAULT 0,
    `dealer_points` tinyint unsigned NOT NULL DEFAULT 0,

    `result` enum('win','loss','push','blackjack') DEFAULT NULL,

    `payout` bigint unsigned NOT NULL DEFAULT 0,
    `profit` bigint NOT NULL DEFAULT 0,

    `created_at` datetime NOT NULL,
    `updated_at` datetime NOT NULL,
    `settled_at` datetime DEFAULT NULL,

    PRIMARY KEY (`id`),

    UNIQUE KEY `uniq_blackjack_active_key` (`active_key`),

    KEY `idx_blackjack_user` (`user_id`),
    KEY `idx_blackjack_user_status` (`user_id`,`status`),
    KEY `idx_blackjack_status` (`status`),
    KEY `idx_blackjack_settled` (`settled_at`)
) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_unicode_ci;