CREATE TABLE `challenges` (
	`id` int AUTO_INCREMENT NOT NULL,
	`challengerId` int NOT NULL,
	`challengedId` int NOT NULL,
	`roomId` int,
	`status` enum('pending','accepted','declined','expired') NOT NULL DEFAULT 'pending',
	`message` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`expiresAt` timestamp,
	CONSTRAINT `challenges_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `follows` (
	`id` int AUTO_INCREMENT NOT NULL,
	`followerId` int NOT NULL,
	`followingId` int NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `follows_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `notifications` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`type` enum('challenge','room_live','riddle_new','follow','general') NOT NULL DEFAULT 'general',
	`title` varchar(200) NOT NULL,
	`message` text,
	`relatedId` int,
	`isRead` boolean NOT NULL DEFAULT false,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `notifications_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `poet_profiles` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`displayName` varchar(100) NOT NULL,
	`bio` text,
	`avatarUrl` text,
	`city` varchar(100),
	`totalBattles` int NOT NULL DEFAULT 0,
	`totalRiddles` int NOT NULL DEFAULT 0,
	`riddlePoints` int NOT NULL DEFAULT 0,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `poet_profiles_id` PRIMARY KEY(`id`),
	CONSTRAINT `poet_profiles_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
CREATE TABLE `recordings` (
	`id` int AUTO_INCREMENT NOT NULL,
	`roomId` int NOT NULL,
	`poetId` int NOT NULL,
	`audioUrl` text NOT NULL,
	`audioKey` text NOT NULL,
	`transcription` text,
	`duration` int,
	`roundNumber` int NOT NULL DEFAULT 1,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `recordings_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `riddle_answers` (
	`id` int AUTO_INCREMENT NOT NULL,
	`riddleId` int NOT NULL,
	`userId` int NOT NULL,
	`answer` text NOT NULL,
	`isCorrect` boolean NOT NULL DEFAULT false,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `riddle_answers_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `riddles` (
	`id` int AUTO_INCREMENT NOT NULL,
	`authorId` int NOT NULL,
	`title` varchar(200) NOT NULL,
	`content` text NOT NULL,
	`difficulty` enum('easy','medium','hard') NOT NULL DEFAULT 'medium',
	`status` enum('open','solved','closed') NOT NULL DEFAULT 'open',
	`correctAnswer` text,
	`winnerId` int,
	`participantCount` int NOT NULL DEFAULT 0,
	`points` int NOT NULL DEFAULT 10,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `riddles_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `rooms` (
	`id` int AUTO_INCREMENT NOT NULL,
	`title` varchar(200) NOT NULL,
	`description` text,
	`status` enum('waiting','live','ended') NOT NULL DEFAULT 'waiting',
	`poet1Id` int NOT NULL,
	`poet2Id` int,
	`currentTurn` int,
	`viewerCount` int NOT NULL DEFAULT 0,
	`roundNumber` int NOT NULL DEFAULT 0,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	`endedAt` timestamp,
	CONSTRAINT `rooms_id` PRIMARY KEY(`id`)
);
