# AssignCostCenterToHierarchyNode

## Overview

assignCostCenterToHierarchyNode moves an existing cost center to a different hierarchy node within the same company's cost center hierarchy. This enables reorganization of the cost center structure without recreating cost center master data.

## Business Rules

- Cost center must exist
- Target hierarchy node must exist within the same company's hierarchy
- Cost center and target node must belong to the same company
- Multiple cost centers can be assigned to the same hierarchy node
- Emits an audit event recording the hierarchy assignment change and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive assign cost center to hierarchy node request] --> B{Cost center exists?}
    B -->|No| C[Return error: COST_CENTER_NOT_FOUND]
    B -->|Yes| D{Target hierarchy node exists?}
    D -->|No| E[Return error: HIERARCHY_NODE_NOT_FOUND]
    D -->|Yes| F{Same company?}
    F -->|No| G[Return error: COMPANY_MISMATCH]
    F -->|Yes| H[Assign cost center to target hierarchy node]
    H --> I[Emit audit event]
    I --> J[Return updated cost center]
```

## External Dependencies

- None

## Error Scenarios

- **COST_CENTER_NOT_FOUND**: Cost center with the specified ID does not exist
- **HIERARCHY_NODE_NOT_FOUND**: Target hierarchy node does not exist
- **COMPANY_MISMATCH**: Cost center and target hierarchy node do not belong to the same company

## Test Cases

- returns error when cost center does not exist
- returns error when target hierarchy node does not exist
- returns error when cost center and node belong to different companies
- assigns cost center to hierarchy node successfully
- updates the hierarchyNodeId field on the cost center
