<?php
session_start();
require_once __DIR__ . '/../../includes/db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $service_id = (int)$_POST['service_id'];
    $sub_dept_id = ((int)$_POST['sub_dept_id'] === 0) ? null : (int)$_POST['sub_dept_id'];

    $stmt = $conn->prepare("UPDATE service_catalog SET lab_sub_dept_id = ? WHERE id = ?");
    $stmt->bind_param("ii", $sub_dept_id, $service_id);
    
    if ($stmt->execute()) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'message' => 'DB Error']);
    }
}