# RescheduleProductionOrder

## Permission Scope

productionOrder

## Overview

RescheduleProductionOrder changes the planned execution dates on a released order before execution starts. The command preserves the released snapshots and keeps the change auditable.

## Business Rules

- Target order must exist and be in `RELEASED`.
- No work order may have started or received execution evidence.
- Revised planned dates must be chronologically valid.
- Rescheduling changes scheduling fields only; BOM, routing, and cost snapshots remain unchanged.

## Process Flow

```mermaid
flowchart TD
    A[Receive reschedule request] --> B{Order exists and is RELEASED?}
    B -->|No| C[Return PRODUCTION_ORDER_NOT_RESCHEDULABLE]
    B -->|Yes| D{Execution already started?}
    D -->|Yes| E[Return EXECUTION_ALREADY_STARTED]
    D -->|No| F[Validate revised dates]
    F --> G[Persist scheduling update]
    G --> H[Return rescheduled order]
```

## External Dependencies

- None

## Error Scenarios

- **PRODUCTION_ORDER_NOT_FOUND**: Referenced production order does not exist
- **PRODUCTION_ORDER_NOT_RESCHEDULABLE**: The order is not in `RELEASED`.
- **EXECUTION_ALREADY_STARTED**: Work-order execution evidence already exists for this production order
- **INVALID_DATE_RANGE**: Planned dates are missing or chronologically invalid.

## Test Cases

- reschedules a released order before execution starts
- returns error when the order does not exist
- returns error when the order is not in `RELEASED`
- returns error when execution has already started
- returns error when planned dates are invalid
- preserves release snapshots after rescheduling
