# ReleaseAccountPayableDocumentHold

## Permission Scope

accountPayableDocument

## Overview

releaseAccountPayableDocumentHold releases a single active payment hold on an AP document. Releasing sets releasedAt and an optional release reason on the hold. A released SYSTEM hold is treated as accepted: subsequent matching reconciliation does not recreate it, so an approved variance no longer blocks posting.

## Business Rules

- The hold must exist
- The hold must be active (releasedAt is null); an already released hold cannot be released again
- Releasing sets releasedAt and stores the optional release reason
- Releasing a SYSTEM hold accepts the underlying variance so reconciliation does not recreate it

## Process Flow

```mermaid
flowchart TD
    A[Receive release hold request] --> B{Hold exists?}
    B -->|No| C[Return error: AP hold not found]
    B -->|Yes| D{Hold is active?}
    D -->|No| E[Return error: AP hold already released]
    D -->|Yes| F[Set releasedAt and release reason]
    F --> G[Return released hold]
```

## External Dependencies

- None

## Error Scenarios

- **AP_HOLD_NOT_FOUND**: Referenced AP document hold does not exist
- **AP_HOLD_ALREADY_RELEASED**: AP document hold is already released

## Test Cases

- releases an active hold and sets releasedAt with the release reason
- returns error when the hold does not exist
- returns error when the hold is already released
