# CreateWarehouse

## Permission Scope

location

## Overview

createWarehouse establishes a new warehouse linked to an organizational site. The warehouse is created in ACTIVE status and is immediately available for storage location creation and stock operations. Each warehouse must have a unique name within its associated site.

## Business Rules

- Name is required and must be unique within the same site
- siteId is required and must reference an existing ACTIVE site
- storageCondition is optional
- capacity is optional

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Validate name provided?}
    B -->|No| C[Return error: name required]
    B -->|Yes| D{Site exists?}
    D -->|No| E[Return error: SITE_NOT_FOUND]
    D -->|Yes| F{Site ACTIVE?}
    F -->|No| G[Return error: SITE_INACTIVE]
    F -->|Yes| H{Name unique within site?}
    H -->|No| I[Return error: DUPLICATE_WAREHOUSE_NAME]
    H -->|Yes| J[Create warehouse with ACTIVE status]
    J --> K[Return created warehouse]
```

## External Dependencies

- [organization::Site](../../../organization/docs/models/Site.md) - Validates that the referenced site exists and is active

## Error Scenarios

- **SITE_NOT_FOUND**: Referenced site does not exist
- **SITE_INACTIVE**: Referenced site exists but is not in ACTIVE status
- **DUPLICATE_WAREHOUSE_NAME**: A warehouse with the same name already exists at the given site

## Test Cases

- returns error when site not found
- returns error when site is inactive
- returns error when warehouse name already exists at site
- creates warehouse with ACTIVE status
- creates warehouse with optional storage condition
- creates warehouse with optional capacity
