CREATE TABLE `canaux_discussion` (
	`id` int AUTO_INCREMENT NOT NULL,
	`titre` varchar(255) NOT NULL,
	`description` text,
	`type` enum('contact_referent','mise_en_relation_public','mise_en_relation_prive') NOT NULL,
	`visibilite` enum('public','prive') NOT NULL DEFAULT 'prive',
	`etablissementId` int,
	`demandeContactId` int,
	`demandeMiseEnRelationId` int,
	`creePar` int NOT NULL,
	`statut` enum('ouvert','ferme') NOT NULL DEFAULT 'ouvert',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `canaux_discussion_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `demandes_mise_en_relation` (
	`id` int AUTO_INCREMENT NOT NULL,
	`demandeurId` int NOT NULL,
	`demandeurNom` varchar(255) NOT NULL,
	`demandeurEmail` varchar(320),
	`etablissementDemandeurId` int,
	`sujet` varchar(500) NOT NULL,
	`message` text NOT NULL,
	`statut` enum('en_attente','traite','ferme') NOT NULL DEFAULT 'en_attente',
	`canalId` int,
	`traitePar` int,
	`traiteAt` timestamp,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `demandes_mise_en_relation_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `membres_canaux_discussion` (
	`id` int AUTO_INCREMENT NOT NULL,
	`canalId` int NOT NULL,
	`userId` int NOT NULL,
	`role` enum('membre','animateur') NOT NULL DEFAULT 'membre',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `membres_canaux_discussion_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `messages_canaux` (
	`id` int AUTO_INCREMENT NOT NULL,
	`canalId` int NOT NULL,
	`auteurId` int NOT NULL,
	`auteurNom` varchar(255) NOT NULL,
	`contenu` text NOT NULL,
	`lu` boolean NOT NULL DEFAULT false,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `messages_canaux_id` PRIMARY KEY(`id`)
);
