# RetireAccrualPlan

## Permission Scope

`accrualPlan`

## Overview

Closes the current open generation of an `AccrualPlan` when the plan is discontinued, preserving all prior generations so that past grants remain historically explainable.

## Business Rules

- Sets `effectiveEnd` on the current open generation (`effectiveEnd IS NULL`) to the retirement date; no generation is ever deleted
- Historical explanations remain intact: prior grants still resolve to whichever generation was effective on their grant date
- After retirement, no new HIRE or ANNIVERSARY grants are produced for the (`leaveTypeKey`, employment type) combination until a new `AccrualPlan` generation is created
- Cannot retire a plan that has no open generation (already retired)

## Process Flow

```mermaid
flowchart TD
    A[Admin retires an AccrualPlan] --> B{Plan has an open generation?}
    B -- No --> R1[Reject: PLAN_ALREADY_RETIRED]
    B -- Yes --> C[Set effectiveEnd = retirement date on the open generation]
    C --> D[Prior generations remain untouched for historical explanation]
    D --> E[Anniversary batch no longer grants for this leaveTypeKey + employment type]
```

## External Dependencies

- [leave-management::AccrualPlan](../model/AccrualPlan.md) - closes the current generation, leaving all prior generations intact

## Error Scenarios

- **ACCRUAL_PLAN_NOT_FOUND**: no AccrualPlan exists for the given id
- **PLAN_ALREADY_RETIRED**: the plan has no open generation to close

## Test Cases

- retiring an active plan closes its current generation with effectiveEnd set
- retiring a plan does not delete or alter prior generations
- retiring an already-retired plan is rejected
- retiring a non-existent AccrualPlan id is rejected
- after retirement, the anniversary batch no longer grants for the retired combination

