<?php
include 'db.php';
header('Content-Type: application/json');

$result = $conn->query("SELECT * FROM products WHERE quantity < min_level");
$low_stock = [];

while($row = $result->fetch_assoc()){
    $low_stock[] = [
        'name' => $row['name'],
        'sku' => $row['sku'],
        'quantity' => $row['quantity'],
        'min_level' => $row['min_level']
    ];
}

echo json_encode($low_stock);
