<?php
require_once 'db_connect.php';

$store_id = isset($_GET['store_id']) ? intval($_GET['store_id']) : 0;
$item_id = isset($_GET['item_id']) ? intval($_GET['item_id']) : 0;

$quantity = 0;
if ($store_id > 0 && $item_id > 0) {
    try {
        $stmt = $conn->prepare("SELECT quantity FROM store_inventory WHERE store_id = :store_id AND item_id = :item_id");
        $stmt->execute([':store_id' => $store_id, ':item_id' => $item_id]);
        $quantity = $stmt->fetchColumn() ?: 0;
    } catch (PDOException $e) {
        error_log("Error fetching quantity: " . $e->getMessage());
    }
}

header('Content-Type: application/json');
echo json_encode(['quantity' => $quantity]);
exit();