CREATE TABLE `apprenants` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nom` varchar(255) NOT NULL,
	`prenom` varchar(255) NOT NULL,
	`email` varchar(320) NOT NULL,
	`codeEtablissement` varchar(50) NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `apprenants_id` PRIMARY KEY(`id`),
	CONSTRAINT `apprenants_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `formations` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nom` varchar(255) NOT NULL,
	`description` text,
	`lienUnique` varchar(100) NOT NULL,
	`actif` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `formations_id` PRIMARY KEY(`id`),
	CONSTRAINT `formations_lienUnique_unique` UNIQUE(`lienUnique`)
);
--> statement-breakpoint
CREATE TABLE `inscriptions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`apprenantId` int NOT NULL,
	`sessionId` int NOT NULL,
	`statut` enum('confirmee','liste_attente','annulee') NOT NULL DEFAULT 'confirmee',
	`dateInscription` timestamp NOT NULL DEFAULT (now()),
	`invitationEnvoyee` boolean NOT NULL DEFAULT false,
	`emailConfirmationEnvoye` boolean NOT NULL DEFAULT false,
	`emailTeaserEnvoye` boolean NOT NULL DEFAULT false,
	`emailRappelEnvoye` boolean NOT NULL DEFAULT false,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `inscriptions_id` PRIMARY KEY(`id`),
	CONSTRAINT `inscriptions_apprenantId_sessionId_unique` UNIQUE(`apprenantId`,`sessionId`)
);
--> statement-breakpoint
CREATE TABLE `sessions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`formationId` int NOT NULL,
	`nom` varchar(255) NOT NULL,
	`dateDebut` datetime NOT NULL,
	`dateFin` datetime NOT NULL,
	`lieu` varchar(500) NOT NULL,
	`capaciteMax` int NOT NULL DEFAULT 12,
	`dateBlocage` datetime NOT NULL,
	`statut` enum('ouverte','bloquee','terminee') NOT NULL DEFAULT 'ouverte',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `sessions_id` PRIMARY KEY(`id`)
);
