-- Create all_games table
CREATE TABLE IF NOT EXISTS `all_games` (
  `id` int NOT NULL AUTO_INCREMENT,
  `gameId` varchar(100) NOT NULL UNIQUE,
  `gameName` varchar(255) NOT NULL,
  `gameType` varchar(50) NOT NULL,
  `category` varchar(50) NOT NULL DEFAULT 'slots',
  `provider` varchar(100) NOT NULL,
  `rtp` decimal(5,2) NOT NULL DEFAULT '96.00',
  `volatility` varchar(20) NOT NULL DEFAULT 'medium',
  `paylines` int NOT NULL DEFAULT '20',
  `reels` int NOT NULL DEFAULT '5',
  `minBet` decimal(10,2) NOT NULL DEFAULT '0.01',
  `maxBet` decimal(10,2) NOT NULL DEFAULT '100.00',
  `jackpot` decimal(15,2) NOT NULL DEFAULT '0',
  `hasIcon` tinyint NOT NULL DEFAULT '0',
  `iconUrl` longtext,
  `isActive` tinyint NOT NULL DEFAULT '1',
  `isFeatured` tinyint NOT NULL DEFAULT '0',
  `playCount` int NOT NULL DEFAULT '0',
  `totalWinnings` decimal(15,2) NOT NULL DEFAULT '0',
  `averageWin` decimal(10,2) NOT NULL DEFAULT '0',
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_all_games_gameId` (`gameId`),
  KEY `idx_all_games_provider` (`provider`),
  KEY `idx_all_games_category` (`category`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create game_library table
CREATE TABLE IF NOT EXISTS `game_library` (
  `id` int NOT NULL AUTO_INCREMENT,
  `userId` int NOT NULL,
  `gameId` varchar(100) NOT NULL,
  `lastPlayedAt` timestamp NULL,
  `favorited` tinyint NOT NULL DEFAULT '0',
  `playCount` int NOT NULL DEFAULT '0',
  `totalBet` decimal(15,2) NOT NULL DEFAULT '0',
  `totalWin` decimal(15,2) NOT NULL DEFAULT '0',
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_game_library_userId` (`userId`),
  KEY `idx_game_library_gameId` (`gameId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create game_stats table
CREATE TABLE IF NOT EXISTS `game_stats` (
  `id` int NOT NULL AUTO_INCREMENT,
  `gameId` varchar(100) NOT NULL,
  `date` varchar(10) NOT NULL,
  `playCount` int NOT NULL DEFAULT '0',
  `uniquePlayers` int NOT NULL DEFAULT '0',
  `totalBet` decimal(15,2) NOT NULL DEFAULT '0',
  `totalWin` decimal(15,2) NOT NULL DEFAULT '0',
  `totalRtp` decimal(5,2) NOT NULL DEFAULT '0',
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_game_stats_gameId` (`gameId`),
  KEY `idx_game_stats_date` (`date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create game_recommendations table
CREATE TABLE IF NOT EXISTS `game_recommendations` (
  `id` int NOT NULL AUTO_INCREMENT,
  `userId` int NOT NULL,
  `gameId` varchar(100) NOT NULL,
  `score` decimal(5,2) NOT NULL DEFAULT '0',
  `reason` varchar(255),
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_game_rec_userId` (`userId`),
  KEY `idx_game_rec_gameId` (`gameId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
