# DeleteTaxonomyNode

## Permission Scope

taxonomy

## Overview

deleteTaxonomyNode permanently removes a taxonomy node from the hierarchy. Deletion is only allowed for leaf nodes (no children) with no item assignments. This ensures the classification tree remains consistent and no item classifications are silently lost.

For node consolidation scenarios, item assignments should first be moved to another node using assignItemToTaxonomy and removeItemFromTaxonomy before deleting the empty node.

## Business Rules

- Target node must exist in the system
- Node must have no child nodes — a node with children cannot be deleted
- Node must have no item assignments — a node with assigned items cannot be deleted
- Deletion is permanent and cannot be undone
- The node's code becomes available for reuse after deletion

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{Node exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{Has child nodes?}
    D -->|Yes| E[Return error: has children]
    D -->|No| F{Has item assignments?}
    F -->|Yes| G[Return error: has assignments]
    F -->|No| H[Delete node record]
    H --> I[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **NODE_NOT_FOUND**: Specified taxonomy node ID does not exist
- **NODE_HAS_CHILDREN**: Node has one or more child nodes — children must be moved or deleted first
- **NODE_HAS_ASSIGNMENTS**: Node has one or more item assignments — assignments must be removed first

## Test Cases

- returns error when node does not exist
- returns error when node has children
- returns error when node has item assignments
- deletes a leaf node with no assignments
