CREATE DATABASE IF NOT EXISTS `vast_manager`;
USE `vast_manager`;

-- Ads Table
CREATE TABLE IF NOT EXISTS `ads` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `title` VARCHAR(255) NOT NULL,
    `video_url` TEXT NOT NULL,
    `duration` INT DEFAULT 30,
    `skip_after` INT DEFAULT 5,
    `click_mode` ENUM('none', 'redirect') DEFAULT 'none',
    `click_url` TEXT DEFAULT NULL,
    `weight` INT DEFAULT 1,
    `status` ENUM('active', 'inactive') DEFAULT 'active',
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Analytics Table
CREATE TABLE IF NOT EXISTS `analytics` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `ad_id` INT NOT NULL,
    `event_type` ENUM('impression', 'start', 'skip', 'complete', 'click') NOT NULL,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (`ad_id`) REFERENCES `ads`(`id`) ON DELETE CASCADE
);
