-- Create database
CREATE DATABASE IF NOT EXISTS parallelpx_admin;
USE parallelpx_admin;

-- Dashboard analytics table
CREATE TABLE IF NOT EXISTS analytics (
    id INT AUTO_INCREMENT PRIMARY KEY,
    metric_name VARCHAR(100) NOT NULL,
    metric_value INT NOT NULL,
    date DATE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Content management table
CREATE TABLE IF NOT EXISTS content (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content TEXT,
    type ENUM('page', 'post', 'video', 'image') DEFAULT 'post',
    status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
    author_id INT,
    featured_image VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (author_id) REFERENCES users(id)
);

-- Settings table
CREATE TABLE IF NOT EXISTS settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100) UNIQUE NOT NULL,
    setting_value TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Logs table for admin activities
CREATE TABLE IF NOT EXISTS activity_logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT,
    action VARCHAR(255) NOT NULL,
    details TEXT,
    ip_address VARCHAR(45),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id)
);

-- Insert sample analytics data
INSERT INTO analytics (metric_name, metric_value, date) VALUES 
('page_views', 1250, CURDATE()),
('users', 320, CURDATE()),
('revenue', 5680, CURDATE()),
('orders', 45, CURDATE());

-- Insert sample content
INSERT INTO content (title, content, type, status, author_id) VALUES 
('Welcome to ParallelPx', 'This is the main welcome content for the website.', 'page', 'published', 1),
('First Blog Post', 'This is our first blog post content.', 'post', 'published', 1),
('About Us Video', 'Company introduction video content.', 'video', 'published', 1);

-- Insert default settings
INSERT INTO settings (setting_key, setting_value) VALUES 
('site_name', 'ParallelPx Admin'),
('site_description', 'Professional admin dashboard'),
('items_per_page', '10'),
('theme', 'light');