# DeleteEligibilityRule

## Permission Scope

`eligibility`

## Overview

Removes an eligibility grant generation entered in error. The removal is rejected when the grant is the sole eligibility a current `WorkRule` assignment relies on, so a live assignment is never left without its eligibility basis.

## Business Rules

- Deletion is rejected if this generation is the sole eligibility grant a current assignment (e.g. a live `assignWorkRule` binding) relies on
- Deleting a generation does not alter the effective ranges of sibling generations sharing the same `versionOf`
- Deletion is for a grant entered in error; a policy change (a role losing eligibility) is expressed via update, which closes-and-inserts rather than deletes

## Process Flow

```mermaid
flowchart TD
    A[Receive eligibility rule id] --> B{Rule exists?}
    B -- No --> C[Reject: ELIGIBILITY_RULE_NOT_FOUND]
    B -- Yes --> D{Is this the sole grant a current assignment relies on?}
    D -- Yes --> E[Reject: SOLE_GRANT_IN_USE]
    D -- No --> F[Delete EligibilityRule generation]
```

## External Dependencies

- [time-tracking::EligibilityRule](../model/EligibilityRule.md) model — the entity this command deletes
- [time-tracking::WorkRule](../model/WorkRule.md) model — checked to determine whether a current assignment depends solely on this grant

## Error Scenarios

- **ELIGIBILITY_RULE_NOT_FOUND**: no EligibilityRule exists for the given id
- **SOLE_GRANT_IN_USE**: the grant is the only eligibility basis for a current assignment and cannot be removed

## Test Cases

- deleting an eligibility grant with no dependent current assignment succeeds
- deleting an eligibility grant that is the sole basis for a current assignment is rejected
- deleting an eligibility grant is allowed when another in-force grant covers the same assignment
- deleting a non-existent eligibility rule id is rejected

