-- Eventos da linha do tempo do app (cadastro, foto, segurança, etc.)
-- Persistem no servidor para consulta após novo login e para o RH / relatórios.

SET NAMES utf8mb4;

USE `ponto-sas`;

CREATE TABLE IF NOT EXISTS `employee_timeline_events` (
  `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `tenant_id` BIGINT UNSIGNED NOT NULL,
  `employee_id` BIGINT UNSIGNED NOT NULL,
  `event_type` VARCHAR(40) NOT NULL DEFAULT 'app',
  `title` VARCHAR(200) NOT NULL,
  `body` VARCHAR(2000) NULL,
  `client_event_id` VARCHAR(96) NULL,
  `event_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

  KEY `idx_ete_employee_event_at` (`tenant_id`, `employee_id`, `event_at`),
  UNIQUE KEY `uk_ete_client` (`tenant_id`, `employee_id`, `client_event_id`),

  CONSTRAINT `fk_ete_tenant`
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_ete_employee`
    FOREIGN KEY (`employee_id`) REFERENCES `employees`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
