# UpdateCostCenter

## Overview

updateCostCenter modifies fields on an existing cost center. Name, description, category, responsible person, department, and validity period can be updated. The cost center code is fixed by the existing record and is not part of the update input.

## Business Rules

- Cost center must exist
- Name, description, category, responsible person, and department can be updated
- Category must be from the defined set: overhead, production, administration, sales, or research
- When updating validTo, it must remain on or after validFrom
- Emits an audit event recording previous and new field values

## Process Flow

```mermaid
flowchart TD
    A[Receive update cost center request] --> B{Lookup by costCenterId}
    B -->|Not found| C[Return error: COST_CENTER_NOT_FOUND]
    B -->|Found| D{Valid name if provided?}
    D -->|No| E[Return error: INVALID_NAME]
    D -->|Yes| F{Valid category if changed?}
    F -->|No| G[Return error: INVALID_CATEGORY]
    F -->|Yes| H{validTo >= validFrom when both set?}
    H -->|No| I[Return error: INVALID_VALIDITY_PERIOD]
    H -->|Yes| J[Apply updates to cost center]
    J --> K[Emit audit event]
    K --> L[Return updated cost center]
```

## External Dependencies

- None

## Error Scenarios

- **COST_CENTER_NOT_FOUND**: Cost center with the specified ID does not exist
- **INVALID_NAME**: Name is empty or blank when provided
- **INVALID_CATEGORY**: Category is not one of the recognized values (overhead, production, administration, sales, research)
- **INVALID_VALIDITY_PERIOD**: validTo is before validFrom

## Test Cases

- returns error when cost center does not exist
- returns error when name is empty string
- returns error when category is invalid
- returns error when validTo is before validFrom
- updates cost center with valid fields
- updates multiple fields at once
