<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include '../connection.php'; // this should define $conn (MySQLi)

// Get POST values
$product_id = isset($_POST['product_id']) ? (int) $_POST['product_id'] : 0;
$service_id = isset($_POST['service_id']) ? (int) $_POST['service_id'] : 0;

if ($product_id <= 0 || $service_id <= 0) {
    echo json_encode(["success" => false, "message" => "Invalid parameters"]);
    exit;
}

$sql = "SELECT price FROM tbl_service_product_prices WHERE service_id = $service_id AND product_id = $product_id LIMIT 1";
$result = $conn->query($sql);

if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo json_encode(["success" => true, "price" => $row['price']]);
} else {
    echo json_encode(["success" => false, "message" => "Price not found"]);
}

$conn->close();
?>
