# DeleteCostCenter

## Overview

deleteCostCenter permanently removes a cost center. A cost center can only be deleted if it has no associated cost postings, budget line items, or allocation rules referencing it. This prevents orphaning of financial records and ensures data integrity.

## Business Rules

- Cost center must exist
- Cost center must have no associated cost postings
- Cost center must have no associated budget line items
- Cost center must have no associated allocation rules referencing it
- Deletion permanently removes the cost center record
- Emits an audit event recording the deletion and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive delete cost center request] --> B{Cost center exists?}
    B -->|No| C[Return error: COST_CENTER_NOT_FOUND]
    B -->|Yes| D{Has associated cost postings?}
    D -->|Yes| E[Return error: COST_CENTER_HAS_POSTINGS]
    D -->|No| F{Has associated budget line items?}
    F -->|Yes| G[Return error: COST_CENTER_HAS_BUDGET_ITEMS]
    F -->|No| H{Has associated allocation rules?}
    H -->|Yes| I[Return error: COST_CENTER_HAS_ALLOCATION_RULES]
    H -->|No| J[Delete cost center]
    J --> K[Emit audit event]
    K --> L[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **COST_CENTER_NOT_FOUND**: Cost center with the specified ID does not exist
- **COST_CENTER_HAS_POSTINGS**: Cost center has associated cost postings and cannot be deleted
- **COST_CENTER_HAS_BUDGET_ITEMS**: Cost center has associated budget line items and cannot be deleted
- **COST_CENTER_HAS_ALLOCATION_RULES**: Cost center is referenced by allocation rules and cannot be deleted

## Test Cases

- returns error when cost center does not exist
- returns error when cost center has postings
- returns error when cost center has budget items
- returns error when cost center has allocation rules
- deletes cost center when no dependencies exist
