CREATE TABLE `guild_members` (
	`id` int AUTO_INCREMENT NOT NULL,
	`guildId` int NOT NULL,
	`userId` int NOT NULL,
	`role` enum('leader','officer','member') NOT NULL DEFAULT 'member',
	`joinedAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `guild_members_id` PRIMARY KEY(`id`),
	CONSTRAINT `idx_guild_members_unique` UNIQUE(`guildId`,`userId`)
);
--> statement-breakpoint
CREATE TABLE `guilds` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(128) NOT NULL,
	`description` text,
	`leaderId` int NOT NULL,
	`logoUrl` text,
	`memberCount` int NOT NULL DEFAULT 1,
	`totalWins` int NOT NULL DEFAULT 0,
	`totalEarnings` decimal(18,2) NOT NULL DEFAULT '0',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `guilds_id` PRIMARY KEY(`id`),
	CONSTRAINT `guilds_name_unique` UNIQUE(`name`)
);
--> statement-breakpoint
CREATE TABLE `player_stats` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`pokerWins` int NOT NULL DEFAULT 0,
	`pokerLosses` int NOT NULL DEFAULT 0,
	`pokerTotalBet` decimal(18,2) NOT NULL DEFAULT '0',
	`pokerTotalWon` decimal(18,2) NOT NULL DEFAULT '0',
	`bingoWins` int NOT NULL DEFAULT 0,
	`bingoTotalBet` decimal(18,2) NOT NULL DEFAULT '0',
	`bingoTotalWon` decimal(18,2) NOT NULL DEFAULT '0',
	`poolSharkWins` int NOT NULL DEFAULT 0,
	`poolSharkTotalBet` decimal(18,2) NOT NULL DEFAULT '0',
	`poolSharkTotalWon` decimal(18,2) NOT NULL DEFAULT '0',
	`sportsbookWins` int NOT NULL DEFAULT 0,
	`sportsbookTotalBet` decimal(18,2) NOT NULL DEFAULT '0',
	`sportsbookTotalWon` decimal(18,2) NOT NULL DEFAULT '0',
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `player_stats_id` PRIMARY KEY(`id`),
	CONSTRAINT `player_stats_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
CREATE INDEX `idx_guild_members_guildId` ON `guild_members` (`guildId`);--> statement-breakpoint
CREATE INDEX `idx_guild_members_userId` ON `guild_members` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_guilds_leaderId` ON `guilds` (`leaderId`);--> statement-breakpoint
CREATE INDEX `idx_guilds_createdAt` ON `guilds` (`createdAt`);--> statement-breakpoint
CREATE INDEX `idx_player_stats_userId` ON `player_stats` (`userId`);