CREATE TABLE `notification_preferences` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`emailNotifications` boolean NOT NULL DEFAULT true,
	`pushNotifications` boolean NOT NULL DEFAULT true,
	`inAppNotifications` boolean NOT NULL DEFAULT true,
	`paymentNotifications` boolean NOT NULL DEFAULT true,
	`gameNotifications` boolean NOT NULL DEFAULT true,
	`promotionalNotifications` boolean NOT NULL DEFAULT false,
	`systemAlerts` boolean NOT NULL DEFAULT true,
	`emailFrequency` enum('instant','daily','weekly','never') NOT NULL DEFAULT 'instant',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `notification_preferences_id` PRIMARY KEY(`id`),
	CONSTRAINT `notification_preferences_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
CREATE TABLE `notifications` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`type` enum('payment_success','payment_failed','bonus_credited','game_win','game_loss','bet_placed','bet_settled','odds_changed','poker_table_joined','poker_hand_result','poker_tournament_update','bingo_card_purchased','bingo_number_called','bingo_win','kyc_approved','kyc_rejected','kyc_pending','account_suspended','account_restored','withdrawal_approved','withdrawal_rejected','system_alert','promotional','admin_broadcast') NOT NULL,
	`title` varchar(255) NOT NULL,
	`message` text NOT NULL,
	`channels` json,
	`data` json,
	`isRead` boolean NOT NULL DEFAULT false,
	`readAt` timestamp,
	`emailSent` boolean NOT NULL DEFAULT false,
	`pushSent` boolean NOT NULL DEFAULT false,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`expiresAt` timestamp,
	CONSTRAINT `notifications_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE INDEX `idx_notif_prefs_userId` ON `notification_preferences` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_notifications_userId` ON `notifications` (`userId`);--> statement-breakpoint
CREATE INDEX `idx_notifications_createdAt` ON `notifications` (`createdAt`);