<?php
include '../db.php';

header('Content-Type: application/json');

$modifier_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($modifier_id <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid modifier ID']);
    exit;
}

try {
    $stmt = $conn->prepare("
        SELECT 
            id,
            name,
            short_name,
            price_adjustment,
            cost_adjustment,
            is_default,
            is_active,
            sort_order,
            prep_time_adjustment
        FROM item_modifiers 
        WHERE id = ?
    ");
    
    $stmt->bind_param("i", $modifier_id);
    $stmt->execute();
    $result = $stmt->get_result();
    
    if ($modifier = $result->fetch_assoc()) {
        echo json_encode(['success' => true, 'modifier' => $modifier]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Modifier not found']);
    }
    
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
