-- BANNED SERIES OTT FLIX - Database Schema
-- RAYT Film & Entertainment
-- Run this in phpMyAdmin to create all tables

CREATE DATABASE IF NOT EXISTS banned_series_ott CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE banned_series_ott;

-- Series table
CREATE TABLE series (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(200) NOT NULL,
    slug VARCHAR(200) NOT NULL UNIQUE,
    description TEXT,
    short_desc VARCHAR(500),
    genre VARCHAR(100),
    rating VARCHAR(10),
    duration VARCHAR(20),
    year INT,
    seasons INT DEFAULT 1,
    status ENUM('banned','restricted','available') DEFAULT 'available',
    thumbnail VARCHAR(255),
    banner VARCHAR(255),
    video_url VARCHAR(500),
    trailer_url VARCHAR(500),
    featured TINYINT(1) DEFAULT 0,
    views INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Episodes table
CREATE TABLE episodes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    series_id INT NOT NULL,
    season INT NOT NULL DEFAULT 1,
    episode_number INT NOT NULL,
    title VARCHAR(200) NOT NULL,
    description TEXT,
    duration VARCHAR(20),
    video_url VARCHAR(500),
    thumbnail VARCHAR(255),
    status ENUM('banned','restricted','available') DEFAULT 'available',
    views INT DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (series_id) REFERENCES series(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Watchlist / My List
CREATE TABLE watchlist (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    series_id INT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    FOREIGN KEY (series_id) REFERENCES series(id) ON DELETE CASCADE,
    UNIQUE KEY unique_watchlist (user_id, series_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Watch history
CREATE TABLE watch_history (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    episode_id INT NOT NULL,
    progress INT DEFAULT 0,
    completed TINYINT(1) DEFAULT 0,
    watched_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    FOREIGN KEY (episode_id) REFERENCES episodes(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Subscriptions / Payments
CREATE TABLE subscriptions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    plan VARCHAR(20) NOT NULL,
    amount DECIMAL(10,2) NOT NULL,
    currency VARCHAR(10) DEFAULT 'INR',
    payment_id VARCHAR(100),
    order_id VARCHAR(100),
    status ENUM('pending','success','failed','refunded') DEFAULT 'pending',
    starts_at DATE NOT NULL,
    expires_at DATE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Contact messages
CREATE TABLE contacts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) NOT NULL,
    phone VARCHAR(20),
    subject VARCHAR(200),
    message TEXT NOT NULL,
    status ENUM('new','read','replied') DEFAULT 'new',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert sample series
INSERT INTO series (title, slug, description, short_desc, genre, rating, duration, year, seasons, status, featured) VALUES
('The Red Tape', 'the-red-tape', 'A whistleblower documentary exposing bureaucratic corruption. The episode that started it all.', 'Exposing bureaucratic corruption', 'Thriller', 'A', '58 min', 2024, 1, 'banned', 1),
('Shadows of Power', 'shadows-of-power', 'Political intrigue meets psychological thriller as a journalist uncovers a far-reaching conspiracy.', 'Political conspiracy thriller', 'Drama', 'A', '62 min', 2024, 1, 'restricted', 1),
('The Unspoken Truth', 'the-unspoken-truth', 'A raw look at systemic injustice through the eyes of survivors. Removed from three platforms.', 'Systemic injustice exposed', 'Documentary', 'A', '55 min', 2024, 1, 'banned', 1),
('Digital Censorship', 'digital-censorship', 'Meta-commentary on content moderation and who decides what the world is allowed to see.', 'Who controls what you see', 'Tech', 'A', '49 min', 2024, 1, 'available', 0),
('The Silenced Voices', 'the-silenced-voices', 'Stories from artists and creators deplatformed for challenging the status quo.', 'Deplatformed creators speak', 'Anthology', 'A', '64 min', 2024, 2, 'banned', 0),
('Borderlines', 'borderlines', 'A geopolitical thriller blurring the line between patriotism and propaganda.', 'Geopolitical thriller', 'Thriller', 'A', '71 min', 2024, 2, 'restricted', 0);

-- Insert sample episodes for Season 1
INSERT INTO episodes (series_id, season, episode_number, title, description, duration, status) VALUES
(1, 1, 1, 'The Red Tape', 'A whistleblower documentary exposing bureaucratic corruption. The episode that started it all.', '58 min', 'banned'),
(2, 1, 1, 'Shadows of Power', 'Political intrigue meets psychological thriller as a journalist uncovers a far-reaching conspiracy.', '62 min', 'restricted'),
(3, 1, 1, 'The Unspoken Truth', 'A raw look at systemic injustice through the eyes of survivors. Removed from three platforms.', '55 min', 'banned'),
(4, 1, 1, 'Digital Censorship', 'Meta-commentary on content moderation and who decides what the world is allowed to see.', '49 min', 'available');

-- Insert sample episodes for Season 2
INSERT INTO episodes (series_id, season, episode_number, title, description, duration, status) VALUES
(5, 2, 1, 'The Silenced Voices', 'Stories from artists and creators deplatformed for challenging the status quo.', '64 min', 'banned'),
(6, 2, 1, 'Borderlines', 'A geopolitical thriller blurring the line between patriotism and propaganda.', '71 min', 'restricted');
