# ApprovalDecision

## Description

ApprovalDecision is the immutable, append-only log of every actor-driven transition on an `ApprovalRequest`. The `decision` enum has seven values — `APPROVE`, `REJECT`, `SEND_BACK`, `DELEGATE`, `WITHDRAW`, `CANCEL`, `RESUBMIT` — and the row carries `approvalRequestId` as a required FK, `approvalStepId` as a nullable FK, and `sentBackToStepId` as a nullable FK recording the step a send-back rewound to.

## Domain Model Definitions

### Model type

AppendOnly

### Command Definitions

- [approveApprovalStep](../command/ApproveApprovalStep.md)
- [rejectApprovalStep](../command/RejectApprovalStep.md)
- [sendBackApprovalStep](../command/SendBackApprovalStep.md)
- [delegateApprovalStep](../command/DelegateApprovalStep.md)
- [withdrawApprovalRequest](../command/WithdrawApprovalRequest.md)
- [cancelApprovalRequest](../command/CancelApprovalRequest.md)
- [resubmitApprovalRequest](../command/ResubmitApprovalRequest.md)

### Query Definitions

- [getApprovalDecisionHistory](../query/GetApprovalDecisionHistory.md)

### Models

- ApprovalDecision

### Invariants

- A row is append-only: once inserted, attempts to update or delete it are rejected
- `approvalRequestId` is required
- `approvalStepId` is set on `APPROVE`, `REJECT`, `SEND_BACK`, and `DELEGATE` rows and is null on `WITHDRAW`, `CANCEL`, and `RESUBMIT` rows
- `decidedByUserId` is required
- `delegatedToUserId` is non-null on `DELEGATE` rows and null on every other decision type
- `sentBackToStepId` is non-null only on `SEND_BACK` rows that rewind to an earlier step (step mode); it is null on requester-mode `SEND_BACK` rows and on every other decision type. When set, it references a step in the same request whose `stepOrder` is less than the acting step's `stepOrder`
- `comment` is required and non-empty on `REJECT`, `SEND_BACK`, and `CANCEL` rows (it carries the structured reason); optional on `APPROVE`, `DELEGATE`, `WITHDRAW`, and `RESUBMIT`
- `decidedAt` is set at insert

### Relationships

- **Belongs To ApprovalRequest**: Every row references exactly one parent request via `approvalRequestId`
- **Belongs To ApprovalStep (optional)**: Step-level rows reference a parent step via `approvalStepId`; null on request-level rows
- **Sent Back To ApprovalStep (optional)**: Step-mode `SEND_BACK` rows reference the rewind target step via `sentBackToStepId`; null on requester-mode send-backs and all other decision types
- **References User (cross-module)**: `decidedByUserId` references the actor and `delegatedToUserId` (when set) references the delegate; both target rows in `user-management` are never hard-deleted
