-- =====================================================================
--  ALTALYS PROTECTION — CSE et conformité (DUERP, réunions, PV)
--  Import via phpMyAdmin > moso8599_altalys > Importer
--  Rejouable : n'efface rien, ne peut pas s'arrêter en cours de route.
-- =====================================================================
SET NAMES utf8mb4;

-- ---------------------------------------------------------------------
-- RÉUNIONS DU COMITÉ SOCIAL ET ÉCONOMIQUE
--   Effectif 11 à 49 salariés : au moins une réunion tous les deux mois
--   (art. L2315-27). Une périodicité plus courte est possible.
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `cse_reunions` (
  `id`            BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `numero`        VARCHAR(20)  NULL,            -- ex. 2026-07
  `type`          ENUM('ordinaire','extraordinaire') NOT NULL DEFAULT 'ordinaire',
  `date_reunion`  DATE NOT NULL,
  `heure_debut`   TIME NULL,
  `heure_fin`     TIME NULL,
  `lieu`          VARCHAR(160) NULL,
  `presents_direction`  TEXT NULL,
  `presents_cse`        TEXT NULL,
  `absents`             TEXT NULL,
  `ordre_du_jour` MEDIUMTEXT NULL,
  `proces_verbal` MEDIUMTEXT NULL,
  `decisions`     MEDIUMTEXT NULL,
  `statut`        ENUM('planifiee','tenue','pv_redige','pv_signe') NOT NULL DEFAULT 'planifiee',
  `document_id`   BIGINT UNSIGNED NULL,          -- PV signé et scanné
  `cree_le`       DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `maj_le`        DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_date` (`date_reunion`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Points inscrits à l'ordre du jour
CREATE TABLE IF NOT EXISTS `cse_points` (
  `id`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `reunion_id` BIGINT UNSIGNED NOT NULL,
  `ordre`      INT NOT NULL DEFAULT 0,
  `intitule`   VARCHAR(255) NOT NULL,
  `expose`     MEDIUMTEXT NULL,
  `decision`   MEDIUMTEXT NULL,
  `suite`      ENUM('clos','a_suivre','reporte') NOT NULL DEFAULT 'clos',
  `echeance`   DATE NULL,
  PRIMARY KEY (`id`),
  KEY `idx_reunion` (`reunion_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ---------------------------------------------------------------------
-- Paramètres de conformité
-- ---------------------------------------------------------------------
INSERT INTO `parametres` (`cle`,`valeur`) VALUES
 ('cse_periodicite_mois','1'),        -- rythme choisi par l'entreprise
 ('cse_preavis_jours','15'),          -- alerte avant la prochaine réunion
 ('duerp_validite_mois','12'),        -- mise à jour annuelle (11 salariés et plus)
 ('duerp_preavis_jours','30'),
 ('effectif_reference','27')
ON DUPLICATE KEY UPDATE `cle` = `cle`;
