# GetSerialNumberHistory

## Overview

GetSerialNumberHistory retrieves the full transaction history for a serial number — all state transitions, stock movements, and location changes. This provides a complete audit trail ordered chronologically.

## Business Rules

- Requires `serialNumberId`
- Returns an ordered list of InventoryLedger entries referencing this serial number, each containing:
  - `executionType` — the type of inventory operation from InventoryExecution (GOODS_RECEIPT, GOODS_ISSUE, etc.)
  - `sourceDocumentId` — reference to the originating document from InventoryExecution
  - `executedAt` — when the movement occurred
  - `storageLocationId` — the storage location involved
  - `quantity` — the quantity moved
- Queries all InventoryLedger records where serialNumberId matches and joins InventoryExecution for source context
- Results are ordered by executedAt ascending (oldest first)
- Returns error if the serial number does not exist
- Returns an empty history for a newly created serial with no movements

## Process Flow

```mermaid
flowchart TD
    A[Receive serialNumberId] --> B{Serial number exists?}
    B -->|No| C[Return SERIAL_NUMBER_NOT_FOUND error]
    B -->|Yes| D[Join InventoryExecution and select InventoryLedger where serialNumberId matches]
    D --> E[Order by executedAt ascending]
    E --> F{Records found?}
    F -->|Yes| G[Return ordered list of history entries]
    F -->|No| H[Return empty history]
```

## External Dependencies

- None

## Error Scenarios

- **SERIAL_NUMBER_NOT_FOUND**: The specified serial number does not exist

## Test Cases

- returns full history ordered by executedAt ascending
- includes executionType and storageLocationId per entry
- includes storage location
- includes execution source document for traceability
- returns error when serial not found
- returns empty history for newly created serial
