<?php
header('Content-Type: application/json');
session_start();

if (!isset($_SESSION['user_id'])) {
    http_response_code(401);
    echo json_encode(['error' => 'Unauthorized']);
    exit();
}

require_once '../config/db.php';

try {
    $db = new Database();
    $pdo = $db->getConnection();
    
    // الحصول على المنتجات التي كميتها أقل من 10
    $stmt = $pdo->query("SELECT name, quantity FROM products WHERE quantity < 10 ORDER BY quantity ASC LIMIT 10");
    $products = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode($products);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
}
