SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS editor_suggestion_events (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  workspace_id BIGINT UNSIGNED NOT NULL,
  suggestion_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NULL,
  apply_mode ENUM('headline','body','cta','link','all') NOT NULL DEFAULT 'all',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_ese_ws_time(workspace_id,created_at),
  INDEX idx_ese_suggestion(suggestion_id),
  CONSTRAINT fk_ese_workspace FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE,
  CONSTRAINT fk_ese_suggestion FOREIGN KEY(suggestion_id) REFERENCES content_intelligence_suggestions(id) ON DELETE CASCADE,
  CONSTRAINT fk_ese_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
