SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS ad_events (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  ad_placement_id INT UNSIGNED NOT NULL,
  event_type ENUM('view','click') NOT NULL,
  occurred_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_ad_events_lookup (ad_placement_id, event_type, occurred_at),
  KEY idx_ad_events_occurred (occurred_at),
  CONSTRAINT fk_ad_events_placement FOREIGN KEY (ad_placement_id) REFERENCES ad_placements(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
