-- Database Schema for Telegram Mini App

CREATE TABLE IF NOT EXISTS users (
    telegram_id BIGINT PRIMARY KEY,
    username VARCHAR(255),
    first_name VARCHAR(255),
    balance DECIMAL(10, 2) DEFAULT 0.00,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS services (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    category VARCHAR(100),
    price_per_1000 DECIMAL(10, 2) NOT NULL,
    min_quantity INT DEFAULT 100,
    max_quantity INT DEFAULT 10000,
    description TEXT,
    is_active TINYINT(1) DEFAULT 1
);

CREATE TABLE IF NOT EXISTS orders (
    id INT AUTO_INCREMENT PRIMARY KEY,
    telegram_id BIGINT,
    service_id INT,
    link VARCHAR(500) NOT NULL,
    quantity INT NOT NULL,
    total_price DECIMAL(10, 2),
    status ENUM('pending', 'processing', 'completed', 'cancelled') DEFAULT 'pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (telegram_id) REFERENCES users(telegram_id),
    FOREIGN KEY (service_id) REFERENCES services(id)
);

-- Seed some initial FB services
INSERT INTO services (name, category, price_per_1000, min_quantity, max_quantity, description) VALUES
('FB Page Followers (Real)', 'Facebook', 5.50, 100, 50000, 'High quality real looking followers for your page.'),
('FB Post Likes (Instant)', 'Facebook', 1.20, 50, 20000, 'Instant likes for your posts. 100% safe.'),
('FB Profile Followers', 'Facebook', 4.80, 100, 10000, 'Real profile followers for personal accounts.'),
('FB Video Views', 'Facebook', 0.50, 500, 100000, 'Increase views on your Facebook videos.');
