# Warehouse

## Description

Warehouse represents a physical storage facility within a site. Each warehouse belongs to exactly one site and has a lifecycle state machine (ACTIVE ↔ INACTIVE). Warehouses can specify storage conditions (ambient, cold, hazardous) and optional capacity. Multiple warehouses may exist under the same site, but each must have a unique name within that site.

Deactivating a warehouse prevents new stock movements into or out of the warehouse but preserves all historical data.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createWarehouse
    Active --> Inactive: deactivateWarehouse
    Inactive --> Active: reactivateWarehouse
```

### Command Definitions

- [createWarehouse](../commands/CreateWarehouse.md) - Create a new warehouse under a site in ACTIVE status
- [updateWarehouse](../commands/UpdateWarehouse.md) - Update mutable fields (name, storageCondition, capacity) of an existing warehouse
- [deactivateWarehouse](../commands/DeactivateWarehouse.md) - Deactivate a warehouse to prevent new stock movements
- [reactivateWarehouse](../commands/ReactivateWarehouse.md) - Reactivate a previously deactivated warehouse

### Query Definitions

- [getWarehouse](../queries/GetWarehouse.md) - Retrieve a warehouse by id with storage locations
- [listWarehouses](../queries/ListWarehouses.md) - List warehouses with optional filters

### Models

- Warehouse

### Invariants

- Name must be unique within the same site
- Must reference an ACTIVE site
- Multiple warehouses per site are allowed
- Deactivating a warehouse prevents new stock movements but preserves history

### Relationships

- **References Site**: Each warehouse references a Site from the organization module
- **Has many StorageLocation**: A warehouse contains multiple storage locations (zones and bins)
