# DeleteProfitCenterHierarchyNode

## Overview

deleteProfitCenterHierarchyNode removes a node from a profit center hierarchy. A node can only be deleted if it has no child nodes and no profit centers assigned to it. This prevents orphaning of child structures and ensures data integrity.

## Business Rules

- Hierarchy node must exist
- Node must have no child nodes; nodes with children cannot be deleted
- Node must have no profit centers assigned to it; nodes with assigned profit centers cannot be deleted
- Deletion permanently removes the node from the hierarchy
- Emits an audit event recording the deletion and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive delete hierarchy node request] --> B{Node exists?}
    B -->|No| C[Return error: NODE_NOT_FOUND]
    B -->|Yes| D{Node has child nodes?}
    D -->|Yes| E[Return error: NODE_HAS_CHILDREN]
    D -->|No| F{Node has assigned profit centers?}
    F -->|Yes| G[Return error: NODE_HAS_ASSIGNED_PROFIT_CENTERS]
    F -->|No| H[Delete hierarchy node]
    H --> I[Emit audit event]
    I --> J[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **NODE_NOT_FOUND**: Hierarchy node with the specified ID does not exist
- **NODE_HAS_CHILDREN**: Node has child nodes that must be reassigned or removed first
- **NODE_HAS_ASSIGNED_PROFIT_CENTERS**: Node has profit centers assigned that must be reassigned first

## Test Cases

- deletes a leaf node with no children and no assigned profit centers
- returns error when node does not exist
- returns error when node has child nodes
- returns error when node has assigned profit centers
- emits audit event recording the deletion and acting user
