# CostCenterHierarchyNode

## Description

CostCenterHierarchyNode represents a single node within a cost center hierarchy tree, supporting parent-child relationships that enable hierarchical roll-up of costs from leaf-level cost centers through intermediate grouping nodes to the root. Each node carries a name, optional parent node reference, hierarchy reference, sort order, and level attribute. Nodes serve as the assignment target for cost centers, allowing flexible organizational grouping by functional area (e.g., Administration, Production, Sales, R&D).

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [createCostCenterHierarchyNode](../commands/CreateCostCenterHierarchyNode.md) - Create a new hierarchy node as a child of an existing node or as the root node
- [deleteCostCenterHierarchyNode](../commands/DeleteCostCenterHierarchyNode.md) - Delete a hierarchy node that has no child nodes or assigned cost centers
- [moveCostCenterHierarchyNode](../commands/MoveCostCenterHierarchyNode.md) - Move a hierarchy node to a different parent within the same hierarchy

### Query Definitions

- [GetCostCenterHierarchy](../queries/GetCostCenterHierarchy.md) - Retrieve hierarchy nodes as part of the full hierarchy tree

### Models

- CostCenterHierarchyNode

### Invariants

- Hierarchy node requires a name
- Hierarchy node must belong to a valid CostCenterHierarchy via hierarchyId
- A hierarchy node cannot be its own parent (no self-referencing)
- A hierarchy node cannot create a circular reference (child cannot be an ancestor of its parent)
- Deleting a hierarchy node that has child nodes is rejected; children must be reassigned or removed first
- Deleting a hierarchy node that has assigned cost centers is rejected; cost centers must be reassigned first
- Hierarchy nodes support parent-child relationships with a sort order and level attribute

### Relationships

- **Belongs to CostCenterHierarchy**: Each node belongs to a CostCenterHierarchy via hierarchyId
- **Self-referencing Parent**: Each node optionally references a parent CostCenterHierarchyNode via parentNodeId
- **Has Many CostCenter**: A hierarchy node can have multiple cost centers assigned to it
