CREATE TABLE `leaderboards` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`leaderboardType` enum('global','weekly','daily','game_specific') NOT NULL,
	`gameId` int,
	`totalWinnings` decimal(15,2) NOT NULL DEFAULT '0.00',
	`totalBets` decimal(15,2) NOT NULL DEFAULT '0.00',
	`winCount` int NOT NULL DEFAULT 0,
	`rank` int NOT NULL DEFAULT 0,
	`period` varchar(20),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `leaderboards_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `tournament_participants` (
	`id` int AUTO_INCREMENT NOT NULL,
	`tournamentId` int NOT NULL,
	`userId` int NOT NULL,
	`score` decimal(15,2) NOT NULL DEFAULT '0.00',
	`finalRank` int,
	`prizeWon` decimal(15,2) DEFAULT '0.00',
	`joinedAt` timestamp NOT NULL DEFAULT (now()),
	`completedAt` timestamp,
	CONSTRAINT `tournament_participants_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `tournament_snapshots` (
	`id` int AUTO_INCREMENT NOT NULL,
	`tournamentId` int NOT NULL,
	`snapshotTime` timestamp NOT NULL DEFAULT (now()),
	`topPlayers` json,
	CONSTRAINT `tournament_snapshots_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `tournaments` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`description` text,
	`gameId` int,
	`status` enum('upcoming','active','completed','cancelled') NOT NULL DEFAULT 'upcoming',
	`startAt` timestamp NOT NULL,
	`endAt` timestamp NOT NULL,
	`entryFeeGc` int NOT NULL DEFAULT 0,
	`maxParticipants` int,
	`currentParticipants` int NOT NULL DEFAULT 0,
	`prizePool` decimal(15,2) NOT NULL DEFAULT '0.00',
	`prizeDistribution` json,
	`leaderboardId` int,
	`createdBy` int NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `tournaments_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `user_vip_status` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`currentVipTierId` int,
	`lifetimeWinnings` decimal(15,2) NOT NULL DEFAULT '0.00',
	`totalBetsPlaced` decimal(15,2) NOT NULL DEFAULT '0.00',
	`weeklyBonusClaimedAt` timestamp,
	`monthlyBonusClaimedAt` timestamp,
	`lastVipUpgradeAt` timestamp,
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `user_vip_status_id` PRIMARY KEY(`id`),
	CONSTRAINT `user_vip_status_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
CREATE TABLE `vip_tiers` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(64) NOT NULL,
	`minLifetimeWinnings` decimal(15,2) NOT NULL,
	`bonusMultiplier` decimal(3,2) NOT NULL DEFAULT '1.00',
	`weeklyBonusGc` int NOT NULL DEFAULT 0,
	`monthlyBonusGc` int NOT NULL DEFAULT 0,
	`exclusiveGames` json,
	`prioritySupport` boolean NOT NULL DEFAULT false,
	`customAvatarFrame` boolean NOT NULL DEFAULT false,
	`badgeIcon` text,
	`description` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `vip_tiers_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
ALTER TABLE `ai_generated_games` MODIFY COLUMN `rtp` decimal(5,2) NOT NULL DEFAULT '96.00';--> statement-breakpoint
ALTER TABLE `game_analytics` MODIFY COLUMN `totalWagered` decimal(15,2) NOT NULL DEFAULT '0.00';--> statement-breakpoint
ALTER TABLE `game_analytics` MODIFY COLUMN `totalWon` decimal(15,2) NOT NULL DEFAULT '0.00';--> statement-breakpoint
ALTER TABLE `game_analytics` MODIFY COLUMN `totalRevenue` decimal(15,2) NOT NULL DEFAULT '0.00';--> statement-breakpoint
ALTER TABLE `game_analytics` MODIFY COLUMN `avgBetSize` decimal(10,2) NOT NULL DEFAULT '0.00';--> statement-breakpoint
ALTER TABLE `game_analytics` MODIFY COLUMN `rtp` decimal(5,2) NOT NULL DEFAULT '96.00';--> statement-breakpoint
ALTER TABLE `player_profiles` MODIFY COLUMN `totalWins` decimal(15,2) NOT NULL DEFAULT '0.00';--> statement-breakpoint
CREATE INDEX `idx_leaderboard_type` ON `leaderboards` (`leaderboardType`);--> statement-breakpoint
CREATE INDEX `idx_leaderboard_userId` ON `leaderboards` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_leaderboard_gameId` ON `leaderboards` (`gameId`);--> statement-breakpoint
CREATE INDEX `idx_tournament_participants_tournamentId` ON `tournament_participants` (`tournamentId`);--> statement-breakpoint
CREATE INDEX `idx_tournament_participants_userId` ON `tournament_participants` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_tournament_snapshots_tournamentId` ON `tournament_snapshots` (`tournamentId`);--> statement-breakpoint
CREATE INDEX `idx_tournament_status` ON `tournaments` (`status`);--> statement-breakpoint
CREATE INDEX `idx_tournament_gameId` ON `tournaments` (`gameId`);--> statement-breakpoint
CREATE INDEX `idx_tournament_startAt` ON `tournaments` (`startAt`);--> statement-breakpoint
CREATE INDEX `idx_user_vip_userId` ON `user_vip_status` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_vip_tier_minWinnings` ON `vip_tiers` (`minLifetimeWinnings`);