# StorageLocation

## Description

StorageLocation represents a specific area within a warehouse where stock is stored. Locations follow a hierarchical structure: zones are top-level locations (parentId is null) and bins are nested under zones. The maximum depth is three levels (warehouse → zone → bin). Each location has a lifecycle state machine (ACTIVE ↔ INACTIVE) and can specify storage conditions and capacity.

Stock cannot be placed into an INACTIVE location. Deactivating a zone does not automatically deactivate its child bins.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createStorageLocation
    Active --> Inactive: deactivateStorageLocation
    Inactive --> Active: reactivateStorageLocation
```

### Command Definitions

- [createStorageLocation](../commands/CreateStorageLocation.md) - Create a new storage location (zone or bin) within a warehouse
- [updateStorageLocation](../commands/UpdateStorageLocation.md) - Update mutable fields (name, code, storageCondition, capacity) of a storage location
- [deactivateStorageLocation](../commands/DeactivateStorageLocation.md) - Deactivate a storage location to prevent new stock placement
- [reactivateStorageLocation](../commands/ReactivateStorageLocation.md) - Reactivate a previously deactivated storage location

### Query Definitions

- [getStorageLocation](../queries/GetStorageLocation.md) - Retrieve a storage location by id with stock levels
- [listStorageLocations](../queries/ListStorageLocations.md) - List storage locations with optional filters

### Models

- StorageLocation

### Invariants

- Name or code must be unique within the same warehouse
- A zone has a null parentId
- A bin must have a parent zone within the same warehouse
- Maximum depth is 3 levels (warehouse → zone → bin)
- Reactivation is only allowed if the parent warehouse is ACTIVE
- Deactivating a zone does NOT auto-deactivate child bins
- Placing stock into an INACTIVE location is rejected

### Relationships

- **Belongs to Warehouse**: Each storage location belongs to a single warehouse
- **Self-referential parent**: Bins reference a parent zone via parentId
- **Has many StockLevel**: A storage location tracks stock levels for multiple items
- **Referenced by StockMoveLine**: Stock move lines reference storage locations as source or destination
