# GetLot

## Overview

GetLot retrieves a single lot by id or by lotNumber + itemId combination. The input is a union type — callers specify either an id or a lotNumber-itemId pair. This serves as the core lot lookup for traceability, expiration checks, and lot lifecycle commands.

## Business Rules

- Accepts one of two lookup variants:
  - `{ id }` — retrieves by unique identifier
  - `{ lotNumber, itemId }` — retrieves by lot number and item combination
- Returns the full Lot record including current stock across locations (associated LotStockLevel records)
- Returns null if no matching lot is found

## Process Flow

```mermaid
flowchart TD
    A[Receive input] --> B{Which field?}
    B -->|id| C[SELECT from Lot where id = input.id]
    B -->|lotNumber + itemId| D[SELECT from Lot where lotNumber = input.lotNumber AND itemId = input.itemId]
    C --> E{Lot found?}
    D --> E
    E -->|Yes| F[Include associated LotStockLevel records]
    F --> G[Return Lot record]
    E -->|No| H[Return null]
```

## External Dependencies

- None

## Error Scenarios

- **LOT_NOT_FOUND**: No lot matches the given criteria — caller receives null

## Test Cases

- returns lot when found by id
- returns lot when found by lotNumber and itemId
- returns null when not found
- includes lot stock levels across locations
