-- Ata IA (MVP) - logs de geração
-- Execute este SQL no banco `jacare`.

CREATE TABLE IF NOT EXISTS `ata_ia_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sessao_id` int(11) NOT NULL,
  `usuario_id` int(11) DEFAULT NULL,
  `modo` varchar(30) NOT NULL DEFAULT 'mvp',
  `prompt` text DEFAULT NULL,
  `resposta_html` mediumtext DEFAULT NULL,
  `meta_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_ata_ia_sessao` (`sessao_id`),
  KEY `idx_ata_ia_created` (`created_at`),
  CONSTRAINT `fk_ata_ia_sessao` FOREIGN KEY (`sessao_id`) REFERENCES `sessoes` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ata_ia_usuario` FOREIGN KEY (`usuario_id`) REFERENCES `usuarios` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
