# CalculateNodeDepth

## Overview

CalculateNodeDepth determines the depth of a taxonomy node in the tree hierarchy by walking up the ancestor chain from a given node to the root. Depth is defined as the number of nodes in the path from root to the target node (root = depth 1). This is essential for enforcing maximum depth constraints when creating or moving taxonomy nodes.

## Business Rules

- Depth is calculated by traversing parentId references from the target node up to the root
- Root nodes (parentId = null) have depth 1
- Each additional ancestor increments the depth by 1
- The traversal stops when a node with parentId = null is reached or a parent is not found
- Used together with maxDepth parameter (default: 10) to enforce tree depth limits

## Process Flow

```mermaid
flowchart TD
    A[Receive nodeId] --> B[Initialize depth = 1, currentId = nodeId]
    B --> C[SELECT node where id = currentId]
    C --> D{Node found?}
    D -->|No| E[Return current depth]
    D -->|Yes| F{parentId is null?}
    F -->|Yes| E
    F -->|No| G[Increment depth]
    G --> H[Set currentId = parentId]
    H --> C
```

## External Dependencies

- None

## Error Scenarios

- **NODE_NOT_FOUND**: Specified taxonomy node ID does not exist

## Test Cases

- returns depth 1 for root node
- returns depth 2 for child of root
- returns depth 3 for grandchild of root
- returns depth 1 when node not found
- handles broken ancestor chain gracefully
