# CreateStorageLocation

## Permission Scope

location

## Overview

createStorageLocation creates a new storage location under an organizational Site. The new location starts in ACTIVE status with optional storage condition and capacity attributes.

## Business Rules

- siteId is required and must reference an existing ACTIVE Site
- name is required and must be unique within the site
- code is optional; when provided, must be unique within the site
- storageCondition and capacity are optional

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Site exists?}
    B -->|No| C[Return error: SITE_NOT_FOUND]
    B -->|Yes| D{Site ACTIVE?}
    D -->|No| E[Return error: SITE_INACTIVE]
    D -->|Yes| F{Name/code unique in site?}
    F -->|No| G[Return error: DUPLICATE_LOCATION_NAME]
    F -->|Yes| H[Create storage location]
    H --> I[Return created location]
```

## External Dependencies

- Organization module: getSite query used to validate the target Site

## Error Scenarios

- **SITE_NOT_FOUND**: Referenced site does not exist
- **SITE_INACTIVE**: Referenced site is not in ACTIVE status
- **DUPLICATE_LOCATION_NAME**: A location with the same name or code already exists in the site

## Test Cases

- returns error when site not found
- returns error when site inactive
- returns error when location name already exists in site
- creates storage location
- creates storage location without code
- creates storage location with storage condition
