# CloseBudget

## Permission Scope

accounting

## Overview

closeBudget transitions a budget from ACTIVE status to CLOSED status. Once closed, no further modifications are permitted and the budget cannot be reopened. This is the terminal state of the budget lifecycle.

## Business Rules

- Budget must exist
- Budget must be in ACTIVE status to be closed
- Transitions status from ACTIVE to CLOSED
- No further modifications are permitted after closure
- A CLOSED budget cannot be reopened
- Emits an audit event recording the status transition and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive close budget request] --> B{Budget exists?}
    B -->|No| C[Return error: BUDGET_NOT_FOUND]
    B -->|Yes| D{Status is ACTIVE?}
    D -->|No| E[Return error: INVALID_STATE]
    D -->|Yes| F[Transition status from ACTIVE to CLOSED]
    F --> G[Emit audit event]
    G --> H[Return closed budget]
```

## External Dependencies

- None

## Error Scenarios

- **BUDGET_NOT_FOUND**: Budget with the specified ID does not exist
- **INVALID_STATE**: Target entity is not in a valid status for this operation

## Test Cases

- closes an ACTIVE budget transitioning it to CLOSED status
- returns error when budget does not exist
- returns error when budget is not in ACTIVE status
- returns error when budget is in DRAFT status
- returns error when budget is in SUBMITTED status
- returns error when budget is in APPROVED status
- returns error when budget is already CLOSED
- emits audit event recording the status transition and acting user
