-- migration_whatsapp.sql
-- À exécuter une seule fois dans phpMyAdmin (onglet SQL) sur shopnet_db

CREATE TABLE IF NOT EXISTS `assistant_conversations` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `boutique_id` INT NOT NULL,
  `canal` ENUM('web','whatsapp') NOT NULL DEFAULT 'web',
  `identifiant_client` VARCHAR(50) NOT NULL COMMENT 'numéro WhatsApp (format 2250...) ou identifiant de session web',
  `historique` TEXT NOT NULL COMMENT 'JSON des derniers échanges [{role, content}, ...]',
  `derniere_activite` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_client_boutique` (`boutique_id`, `canal`, `identifiant_client`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  COMMENT='Historique de conversation par client, nécessaire pour le multi-tour sur WhatsApp (webhook sans session)';
