-- Create email_campaigns table
CREATE TABLE IF NOT EXISTS `email_campaigns` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `template` longtext NOT NULL,
  `recipientSegment` enum('all','vip','new','inactive','high-value') NOT NULL DEFAULT 'all',
  `status` enum('draft','scheduled','sent') NOT NULL DEFAULT 'draft',
  `scheduledTime` timestamp NULL,
  `sentAt` timestamp NULL,
  `recipientCount` int DEFAULT 0,
  `openCount` int DEFAULT 0,
  `clickCount` int DEFAULT 0,
  `createdBy` int NOT NULL,
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_email_campaigns_status` (`status`),
  KEY `idx_email_campaigns_createdBy` (`createdBy`),
  KEY `idx_email_campaigns_scheduledTime` (`scheduledTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Create banner_analytics table
CREATE TABLE IF NOT EXISTS `banner_analytics` (
  `id` int NOT NULL AUTO_INCREMENT,
  `bannerId` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `impressions` int NOT NULL DEFAULT 0,
  `clicks` int NOT NULL DEFAULT 0,
  `conversions` int NOT NULL DEFAULT 0,
  `revenue` decimal(10,2) NOT NULL DEFAULT 0.00,
  `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_banner_analytics_bannerId` (`bannerId`),
  KEY `idx_banner_analytics_date` (`date`),
  KEY `idx_banner_analytics_bannerId_date` (`bannerId`, `date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
