<?php
header('Content-Type: application/json');
require_once "../../config/database.php";
require_once "../../includes/auth.php";
require_once "../../classes/Inventory.php";

checkRole(['admin', 'warehouse']);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $database = new Database();
    $db = $database->getConnection();
    
    $inventory = new Inventory($db);
    $inventory->inventory_id = $_POST['inventory_id'];
    $inventory->quantity = $_POST['quantity'];
    
    if ($inventory->updateQuantity()) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Failed to update quantity']);
    }
} else {
    http_response_code(405);
    echo json_encode(['success' => false, 'message' => 'Method not allowed']);
}
?>