# CloseStockReservation

## Permission Scope

stockReservation

## Overview

closeStockReservation removes one reservation slice from open availability calculations without deleting the reservation row. Source modules call this command when the slice is closed, cancelled, consumed, or otherwise no longer contributes reservation demand.

## Business Rules

- Input is `{ id }`
- Reservation must exist for the provided `id`
- Reservation must be OPEN
- Sets `status = CLOSED`
- Does not change `reservedQuantity` or `consumedQuantity`
- Does not create InventoryLedger entries or mutate StockLevel

## Process Flow

```mermaid
flowchart TD
    A[Receive close request] --> B{Reservation exists?}
    B -->|No| C[Return error: STOCK_RESERVATION_NOT_FOUND]
    B -->|Yes| D{Reservation OPEN?}
    D -->|No| E[Return error: STOCK_RESERVATION_NOT_OPEN]
    D -->|Yes| F[Set status CLOSED]
    F --> G[Return closed reservation]
```

## External Dependencies

- None

## Error Scenarios

- **STOCK_RESERVATION_NOT_FOUND**: Referenced stock reservation does not exist
- **STOCK_RESERVATION_NOT_OPEN**: Stock reservation is not OPEN

## Test Cases

- closes reservation by id
- returns error when reservation not found
- returns error when reservation is closed
