# FinalizeVarianceReport

## Overview

finalizeVarianceReport transitions a variance report from DRAFT status to FINAL status. Once finalized, the report cannot be modified or transitioned back to DRAFT. This locks the variance analysis results for distribution to management.

## Business Rules

- Variance report must exist
- Variance report must be in DRAFT status to be finalized
- Finalizing an already FINAL report is rejected as an invalid state transition
- Once finalized, no modifications are permitted
- A FINAL report cannot be transitioned back to DRAFT
- Emits an audit event recording the status transition and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive finalize variance report request] --> B{Variance report exists?}
    B -->|No| C[Return error: VARIANCE_REPORT_NOT_FOUND]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return error: INVALID_STATE]
    D -->|Yes| F[Transition status from DRAFT to FINAL]
    F --> G[Emit audit event]
    G --> H[Return finalized variance report]
```

## External Dependencies

- None

## Error Scenarios

- **VARIANCE_REPORT_NOT_FOUND**: Variance report with the specified ID does not exist
- **INVALID_STATE**: Variance report is not in DRAFT status (e.g., already FINAL)

## Test Cases

- finalizes a DRAFT variance report transitioning it to FINAL status
- returns error when variance report does not exist
- returns error when variance report is already FINAL
- finalized report cannot be transitioned back to DRAFT
- emits audit event recording the status transition and acting user
