# RejectSalesOrder

## Permission Scope

salesOrder

## Overview

RejectSalesOrder returns a submitted sales order to DRAFT with an explicit rejection reason. It preserves review feedback without discarding the commercial work already entered on the order.

## Business Rules

- Only SUBMITTED orders may be rejected.
- A non-empty rejection reason is required.
- Rejecting the order must preserve existing lines and snapshots already prepared in draft.

## Process Flow

```mermaid
flowchart TD
    A[Receive reject request] --> B[Load sales order]
    B --> C{Status is SUBMITTED?}
    C -->|No| D[Return INVALID_ORDER_STATUS]
    C -->|Yes| E{Reason provided?}
    E -->|No| F[Return REJECTION_REASON_REQUIRED]
    E -->|Yes| G[Store rejection reason and set status to DRAFT]
    G --> H[Return rejected order]
```

## External Dependencies

- None

## Error Scenarios

- **SALES_ORDER_NOT_FOUND**: Referenced sales order does not exist.
- **INVALID_ORDER_STATUS**: Sales order status does not allow this operation
- **REJECTION_REASON_REQUIRED**: A rejection reason is required.

## Test Cases

- rejects a submitted order and returns it to DRAFT
- stores the rejection reason
- throws when rejecting an order outside SUBMITTED status
- throws when rejection reason is empty
