CREATE TABLE `bookmarks` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`contentId` int,
	`verificationSessionId` int,
	`note` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `bookmarks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `chat_messages` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`verificationSessionId` int NOT NULL,
	`role` enum('user','assistant','system') NOT NULL,
	`content` text NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `chat_messages_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `citations` (
	`id` int AUTO_INCREMENT NOT NULL,
	`contentId` int,
	`verificationSessionId` int,
	`author` varchar(255) NOT NULL,
	`date` varchar(50) NOT NULL,
	`publication` varchar(255) NOT NULL,
	`link` text NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `citations_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `craap_evaluation` (
	`id` int AUTO_INCREMENT NOT NULL,
	`contentId` int NOT NULL,
	`currencyPass` boolean NOT NULL DEFAULT false,
	`relevancePass` boolean NOT NULL DEFAULT false,
	`authorityPass` boolean NOT NULL DEFAULT false,
	`accuracyPass` boolean NOT NULL DEFAULT false,
	`purposePass` boolean NOT NULL DEFAULT false,
	`reasoning` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `craap_evaluation_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `ingested_content` (
	`id` int AUTO_INCREMENT NOT NULL,
	`sourceId` varchar(255) NOT NULL,
	`contentType` enum('news','academic') NOT NULL,
	`title` text NOT NULL,
	`summary` text,
	`url` text NOT NULL,
	`author` varchar(255),
	`publication` varchar(255),
	`publishedAt` timestamp NOT NULL,
	`ingestedAt` timestamp NOT NULL DEFAULT (now()),
	`fullText` text,
	`topics` varchar(500),
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `ingested_content_id` PRIMARY KEY(`id`),
	CONSTRAINT `ingested_content_sourceId_unique` UNIQUE(`sourceId`)
);
--> statement-breakpoint
CREATE TABLE `search_filters` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`name` varchar(255) NOT NULL,
	`topics` text,
	`contentType` enum('news','academic','all') DEFAULT 'all',
	`minCraapScore` int DEFAULT 0,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `search_filters_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `uploaded_files` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`fileType` enum('pdf','image') NOT NULL,
	`filename` varchar(255) NOT NULL,
	`s3Url` text NOT NULL,
	`s3Key` varchar(500) NOT NULL,
	`extractedText` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `uploaded_files_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `verification_sessions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`query` text NOT NULL,
	`submittedUrl` text,
	`uploadedFileId` int,
	`aiResponse` text,
	`craapCurrency` boolean,
	`craapRelevance` boolean,
	`craapAuthority` boolean,
	`craapAccuracy` boolean,
	`craapPurpose` boolean,
	`craapReasoning` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `verification_sessions_id` PRIMARY KEY(`id`)
);
