# GetShiftPatternByCode

## Overview

getShiftPatternByCode resolves a ShiftPattern by its stable `code` rather than its id. It is used wherever pattern selection or labeling binds to the semantic key instead of the display name (ADR-015) — for example, a planner picking "夜勤" from a code-driven picker, or a downstream integration referencing patterns by code.

## Business Rules

- Accepts a `code` as input (the stable, unique key — not the display `name`)
- Returns the single pattern whose `code` matches, with its ordered segments resolved, identical in shape to `getShiftPattern`
- `code` lookups must never fall back to matching on `name`; renaming a pattern's display name does not change which `code` resolves to it
- `code` is unique, so at most one pattern matches

## Process Flow

```mermaid
flowchart TD
    A[Receive code] --> B[Look up ShiftPattern by code]
    B --> C{Found?}
    C -->|No| D[Return error: SHIFT_PATTERN_NOT_FOUND]
    C -->|Yes| E[Return embedded segments ordered by sequence]
    E --> F[Return pattern with segments]
```

## External Dependencies

None — segments are embedded directly in the ShiftPattern (ADR-022).

## Error Scenarios

- **SHIFT_PATTERN_NOT_FOUND**: no ShiftPattern exists for the given id

## Test Cases

- returns the ShiftPattern for a given code
- returns the same pattern whether looked up by id or by code
- resolution is unaffected by a subsequent rename of the pattern's display name
- throws SHIFT_PATTERN_NOT_FOUND for an unknown code
