# DeleteAllocationRule

## Permission Scope

accounting

## Overview

deleteAllocationRule removes an allocation rule from an allocation cycle. Rules can only be removed when the cycle is in DRAFT status.

## Business Rules

- Allocation rule must exist
- Parent allocation cycle must be in DRAFT status
- Rules cannot be removed from cycles in VALIDATED, EXECUTED, POSTED, or REVERSED status
- Deletion permanently removes the rule from the cycle
- Emits an audit event recording the rule deletion and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive delete allocation rule request] --> B{Allocation rule exists?}
    B -->|No| C[Return error: ALLOCATION_RULE_NOT_FOUND]
    B -->|Yes| D{Parent cycle status is DRAFT?}
    D -->|No| E[Return error: INVALID_STATE]
    D -->|Yes| F[Delete allocation rule]
    F --> G[Emit audit event]
    G --> H[Return success]
```

## External Dependencies

- None

## Error Scenarios

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

## Test Cases

- deletes an allocation rule from a DRAFT allocation cycle
- returns error when allocation rule does not exist
- returns error when parent cycle is in VALIDATED status
- returns error when parent cycle is in EXECUTED status
- returns error when parent cycle is in POSTED status
- returns error when parent cycle is in REVERSED status
- emits audit event recording the rule deletion and acting user
