# UpdatePurchaseChangeOrder

## Permission Scope

purchaseOrder

## Overview

UpdatePurchaseChangeOrder revises the lines and reason of an existing `DRAFT` change order, allowing the requester to add, remove, or modify proposed change order lines before submission.

## Business Rules

- Target change order must exist
- Only change orders in `DRAFT` status can be updated
- Can add new change order lines, remove existing change order lines, or modify proposed values on existing change order lines
- Reason text can be updated

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Change order exists?}
    B -->|No| C[Return CO_NOT_FOUND]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return CO_NOT_DRAFT]
    D -->|Yes| F[Update change order lines and reason]
    F --> G[Return updated change order]
```

## External Dependencies

- None

## Error Scenarios

- **CO_NOT_FOUND**: Target change order does not exist
- **CO_NOT_DRAFT**: Change order is not in `DRAFT` status

## Test Cases

- updates reason on a draft change order
- replaces change order lines on an existing draft change order
- removes all change order lines when empty array is provided
- returns error when change order does not exist
- returns error when change order is not in DRAFT status
