CREATE TABLE IF NOT EXISTS users (
    email VARCHAR(255) PRIMARY KEY,
    name VARCHAR(255),
    picture TEXT,
    fingerprint VARCHAR(255),
    plan ENUM('free', 'pro') DEFAULT 'free',
    prompts_used_today INT DEFAULT 0,
    daily_limit INT DEFAULT NULL,
    plan_expires DATETIME DEFAULT NULL,
    banned TINYINT(1) DEFAULT 0,
    ban_reason TEXT DEFAULT NULL,
    last_reset DATETIME DEFAULT CURRENT_TIMESTAMP,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Default admin credentials: admin / turboflow123 (CHANGE THIS!)

CREATE TABLE IF NOT EXISTS admin_emails (
    id INT AUTO_INCREMENT PRIMARY KEY,
    email VARCHAR(255) UNIQUE NOT NULL,
    added_by VARCHAR(100),
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO admin_emails (email, added_by) VALUES ('ummaaahhh.cc@gmail.com', 'system') ON DUPLICATE KEY UPDATE email=email;

CREATE TABLE IF NOT EXISTS packages (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description TEXT,
    price VARCHAR(50),
    duration VARCHAR(100),
    checkout_url TEXT NOT NULL,
    badge VARCHAR(50) DEFAULT '',
    features TEXT,
    sort_order INT DEFAULT 0,
    active TINYINT(1) DEFAULT 1,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT INTO packages (name, description, price, duration, checkout_url, badge, features, sort_order) VALUES
('PRO Monthly', 'Monthly premium subscription', '$12', 'per month', 'https://toolsbd.lemonsqueezy.com/checkout/buy/42d065ad-252a-4624-8a2f-ac81cf34d80c', '', '["Unlimited prompts","4K Upscale","Priority queue","No ads"]', 1),
('PRO Yearly', 'Yearly premium — save 40%', '$72', 'per year', '', 'BEST VALUE', '["Unlimited prompts","4K Upscale","Priority queue","No ads","2 months free"]', 2);

CREATE TABLE IF NOT EXISTS payment_gateways (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    icon VARCHAR(50) DEFAULT '💳',
    type ENUM('lemonsqueezy', 'manual', 'custom') DEFAULT 'custom',
    checkout_url TEXT,
    instructions TEXT,
    admin_note TEXT,
    sort_order INT DEFAULT 0,
    active TINYINT(1) DEFAULT 1,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT INTO payment_gateways (name, icon, type, checkout_url, instructions, sort_order) VALUES
('LemonSqueezy', '🍋', 'lemonsqueezy', 'https://toolsbd.lemonsqueezy.com/checkout/buy/42d065ad-252a-4624-8a2f-ac81cf34d80c', 'Pay securely with card via LemonSqueezy', 1),
('bKash', '📱', 'manual', '', 'Send money to: 01XXXXXXXXX\nAmount: [PRICE]\nAfter payment, send screenshot to support', 2),
('Nagad', '📱', 'manual', '', 'Send money to: 01XXXXXXXXX\nAmount: [PRICE]\nAfter payment, send screenshot to support', 3);
