false, 'ERROR' => 'missing_params', 'MESSAGE' => 'BusinessID is required']); } $categoryID = (int) ($data['TaskCategoryID'] ?? 0); if ($categoryID <= 0) { apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'TaskCategoryID is required']); } try { // Verify ownership $qCheck = queryOne(" SELECT ID FROM TaskCategories WHERE ID = ? AND BusinessID = ? ", [$categoryID, $bizID]); if (!$qCheck) { apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Category not found']); } // Check if any tasks use this category $qTasks = queryOne("SELECT COUNT(*) as cnt FROM Tasks WHERE CategoryID = ?", [$categoryID]); if ((int) $qTasks['cnt'] > 0) { // Soft delete queryTimed("UPDATE TaskCategories SET IsActive = 0 WHERE ID = ?", [$categoryID]); jsonResponse(['OK' => true, 'MESSAGE' => "Category deactivated (has {$qTasks['cnt']} tasks)"]); } else { // Hard delete queryTimed("DELETE FROM TaskCategories WHERE ID = ?", [$categoryID]); jsonResponse(['OK' => true, 'MESSAGE' => 'Category deleted']); } } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]); }