# CreateLot

## Permission Scope

inventoryMaster

## Overview

createLot creates a new lot/batch record for a lot-tracked item. Lots enable tracking of groups of items that share common characteristics such as manufacturing date, expiration date, and supplier lot references. Each lot is uniquely identified by its lot number within a specific item.

## Business Rules

- lotNumber is required and must be unique per item
- itemId is required and must reference an existing item
- manufactureDate and expirationDate are optional
- supplierLotReference is optional

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Item exists?}
    B -->|No| C[Return error: ITEM_NOT_FOUND]
    B -->|Yes| D{lotNumber unique for item?}
    D -->|No| E[Return error: DUPLICATE_LOT_NUMBER]
    D -->|Yes| F[Create lot record]
    F --> G[Return created lot]
```

## External Dependencies

- [item-management::Item](../../../item-management/docs/model/Item.md) - Validates that the referenced item exists

## Error Scenarios

- **ITEM_NOT_FOUND**: Referenced item does not exist
- **DUPLICATE_LOT_NUMBER**: A lot with the same number already exists for this item

## Test Cases

- returns error when item not found
- returns error when lot number already exists for item
- creates lot with all attributes
- creates lot with minimal attributes
