CREATE TABLE IF NOT EXISTS admins (id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, name VARCHAR(255) DEFAULT 'Admin', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS lists (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS list_contacts (id INT AUTO_INCREMENT PRIMARY KEY, list_id INT, email VARCHAR(255), name VARCHAR(255), unsubscribed TINYINT(1) DEFAULT 0, bounced TINYINT(1) DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS templates (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), html LONGTEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS template_images (id INT AUTO_INCREMENT PRIMARY KEY, template_id INT, filename VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS campaigns (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), template_id INT, list_id INT, subject VARCHAR(255), status VARCHAR(50) DEFAULT 'draft', total INT DEFAULT 0, sent INT DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS campaign_logs (id INT AUTO_INCREMENT PRIMARY KEY, campaign_id INT, contact_id INT, message_id VARCHAR(255), status VARCHAR(50) DEFAULT 'pending', opened TINYINT(1) DEFAULT 0, unsubscribed TINYINT(1) DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
