<?php
include('../include/auth.php'); 
include('../include/lskfjwfe.php'); // Ensure correct database connection

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

// Validate input
if (!isset($_POST['service_group_id']) || !is_numeric($_POST['service_group_id'])) {
    echo json_encode(["error" => "Invalid service group ID", "debug" => $_POST]);
    exit;
}

$service_group_id = intval($_POST['service_group_id']);

// Fetch service tasks
$query = $db2->prepare("SELECT service_task_id, service_task_name FROM service_tasks WHERE service_task_grp = ?");
$query->bind_param("i", $service_group_id);
$query->execute();
$result = $query->get_result();

$tasks = [];
while ($row = $result->fetch_assoc()) {
    $tasks[] = $row;
}

if (empty($tasks)) {
    echo json_encode(["error" => "No tasks found", "debug" => $service_group_id]);
    exit;
}

echo json_encode($tasks);
?>
