CREATE TABLE `access_codes` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(320) NOT NULL,
	`code` varchar(64) NOT NULL,
	`expiresAt` timestamp NOT NULL,
	`usedAt` timestamp,
	`ipAddress` varchar(45),
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `access_codes_id` PRIMARY KEY(`id`),
	CONSTRAINT `access_codes_code_unique` UNIQUE(`code`)
);
--> statement-breakpoint
CREATE TABLE `admin_users` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(320) NOT NULL,
	`passwordHash` varchar(255) NOT NULL,
	`name` text,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`lastLoginAt` timestamp,
	CONSTRAINT `admin_users_id` PRIMARY KEY(`id`),
	CONSTRAINT `admin_users_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `course_access_logs` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(320) NOT NULL,
	`courseLevel` varchar(50) NOT NULL,
	`slideId` int,
	`ipAddress` varchar(45),
	`userAgent` text,
	`accessedAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `course_access_logs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `verified_members` (
	`id` int AUTO_INCREMENT NOT NULL,
	`email` varchar(320) NOT NULL,
	`addedBy` int,
	`addedAt` timestamp NOT NULL DEFAULT (now()),
	`isActive` enum('active','suspended') NOT NULL DEFAULT 'active',
	`notes` text,
	CONSTRAINT `verified_members_id` PRIMARY KEY(`id`),
	CONSTRAINT `verified_members_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
ALTER TABLE `verified_members` ADD CONSTRAINT `verified_members_addedBy_users_id_fk` FOREIGN KEY (`addedBy`) REFERENCES `users`(`id`) ON DELETE no action ON UPDATE no action;