CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    password VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE license_keys (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(50) UNIQUE NOT NULL,
    status ENUM('unused', 'active', 'suspended') DEFAULT 'unused',
    used_by_user_id INT DEFAULT NULL
);

CREATE TABLE settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    whatsapp_token TEXT,
    phone_number_id VARCHAR(50),
    gemini_api_key VARCHAR(100),
    product_name VARCHAR(255),
    product_price VARCHAR(50),
    product_description TEXT,
    sales_goal TEXT,
    FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE conversations (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    user_phone VARCHAR(20),
    sender ENUM('user', 'ai'),
    message TEXT,
    timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);