# StorageLocation

## Description

StorageLocation represents a logical storage type within an organizational Site where stock is held. Fields: `name` (unique within site), optional `code` (unique within site), `siteId` (FK to Site), optional `storageCondition` (ambient / cold / hazardous), optional `capacity`, `status` (ACTIVE / INACTIVE lifecycle).

StorageLocations are deliberately flat — zone/bin hierarchy and self-referential parent links are not modeled. Applications that need grouping use naming conventions or custom fields. StorageLocation also does not carry a functional role (receiving / QC / storage) as a schema field; operators name locations conventionally (e.g., "Receiving Dock A") for human clarity, and the schema does not enforce or derive any role from location naming.

Stock cannot be placed into an INACTIVE location.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

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

| Operation | From | To | Command |
|-----------|------|----|---------|
| deactivate | ACTIVE | INACTIVE | [deactivateStorageLocation](../command/DeactivateStorageLocation.md) |
| reactivate | INACTIVE | ACTIVE | [reactivateStorageLocation](../command/ReactivateStorageLocation.md) |

### Command Definitions

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

### Query Definitions

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

### Models

- StorageLocation

### Invariants

- Name is unique within the same site
- Code, when provided, is unique within the same site
- Reactivation requires the parent Site to be ACTIVE
- Placing stock into an INACTIVE location is rejected

### Relationships

- **Belongs to Site**: Each storage location belongs to a single organizational Site
- **Has many StockLevel**: A storage location holds zero or more StockLevel rows
- **Referenced by StockAdjustmentLine**: Stock adjustment lines reference locations as source / destination
