CREATE TABLE `blocs_fonctionnels` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nom` varchar(255) NOT NULL,
	`estValide` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `blocs_fonctionnels_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `consultations` (
	`id` int AUTO_INCREMENT NOT NULL,
	`etablissementId` int NOT NULL,
	`consultePar` int NOT NULL,
	`consulteParNom` varchar(255),
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `consultations_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `demandes_contact` (
	`id` int AUTO_INCREMENT NOT NULL,
	`etablissementCibleId` int NOT NULL,
	`demandeurId` int NOT NULL,
	`demandeurNom` varchar(255),
	`demandeurEmail` varchar(320),
	`message` text NOT NULL,
	`statut` enum('en_attente','repondu','ferme') NOT NULL DEFAULT 'en_attente',
	`reponse` text,
	`reponsePar` int,
	`reponduAt` timestamp,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `demandes_contact_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `editeurs` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nom` varchar(255) NOT NULL,
	`estValide` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `editeurs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `etablissements` (
	`id` int AUTO_INCREMENT NOT NULL,
	`finess` varchar(20),
	`nom` varchar(255) NOT NULL,
	`region` varchar(100),
	`departement` varchar(100),
	`typeActivite` varchar(100),
	`tailleEffectifs` varchar(50),
	`referentId` int,
	`visibilite` enum('tous','gestionnaires') NOT NULL DEFAULT 'tous',
	`accepteMiseEnRelation` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `etablissements_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `logiciels_etablissements` (
	`id` int AUTO_INCREMENT NOT NULL,
	`etablissementId` int NOT NULL,
	`solutionId` int NOT NULL,
	`etatDeploiement` enum('demarrage','en_cours','operationnel','en_remplacement') NOT NULL,
	`modeHebergement` enum('hds','on_premise','hybride'),
	`modeFacturation` enum('saas','achat_maintenance','location'),
	`interoperabilite` enum('non','oui_interface','oui_eai'),
	`versionMajeure` varchar(50),
	`commentaire` text,
	`contactNom` varchar(255),
	`contactFonction` varchar(255),
	`contactEmail` varchar(320),
	`saisiePar` int,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `logiciels_etablissements_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `solutions` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nom` varchar(255) NOT NULL,
	`editeurId` int NOT NULL,
	`blocFonctionnelId` int,
	`estValide` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `solutions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
ALTER TABLE `users` ADD `sonumRole` enum('referent','gestionnaire') DEFAULT 'referent' NOT NULL;--> statement-breakpoint
ALTER TABLE `users` ADD `cguAccepted` boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE `users` ADD `cguAcceptedAt` timestamp;