# CompleteInventoryCount

## Overview

completeInventoryCount completes the inventory count process, transitioning it from IN_PROGRESS to COMPLETED status. All count lines must be in a terminal status (APPROVED or REJECTED) before the count can be completed. If stock was frozen during the count, it is unfrozen upon completion.

## Business Rules

- Count must be in IN_PROGRESS status
- All count lines must be in terminal status (APPROVED or REJECTED)
- Unfreezes stock movements if they were frozen during the count
- Count becomes immutable after completion

## Process Flow

```mermaid
flowchart TD
    A[Receive complete request] --> B{Count exists?}
    B -->|No| C[Return error: COUNT_NOT_FOUND]
    B -->|Yes| D{Status is IN_PROGRESS?}
    D -->|No| E[Return error: COUNT_NOT_IN_PROGRESS]
    D -->|Yes| F{All lines resolved?}
    F -->|No| G[Return error: UNRESOLVED_COUNT_LINES]
    F -->|Yes| H{Stock was frozen?}
    H -->|Yes| I[Unfreeze stock movements]
    I --> J[Update status to COMPLETED]
    H -->|No| J
    J --> K[Return completed count]
```

## External Dependencies

- None

## Error Scenarios

- **COUNT_NOT_FOUND**: Referenced count does not exist
- **COUNT_NOT_IN_PROGRESS**: Count is not in IN_PROGRESS status
- **UNRESOLVED_COUNT_LINES**: One or more count lines are not in a terminal status (APPROVED or REJECTED)

## Test Cases

- returns error when not found
- returns error when not in progress
- returns error when unresolved lines exist
- completes count
- unfreezes stock after completion
