# Soft Delete Registration

Soft-deletes a single registration by setting its `deletedAt` timestamp. The row is **not** removed from the database — it is marked deleted and excluded from all normal queries (which filter `deletedAt IS NULL`). If the registration was holding a seat, that seat is released back to its program/session.

---

## Endpoint

| | |
|---|---|
| **Method** | `DELETE` |
| **Path** | `/registration/:id` |
| **Auth** | Bearer token (required) — header `Authorization: Bearer <token>` |
| **Roles** | `admin`, `shoba`, `rm` only |

### Path parameter

| Param | Type | Required | Notes |
|---|---|---|---|
| `id` | `number` (integer) | ✅ | Registration ID. Non-integer values are rejected with `400`. |

No request body.

---

## Success Response — `200 OK`

```jsonc
{
  "statusCode": 200,
  "message": "Program registration deleted successfully",
  "data": { "id": 101 }
}
```

`data.id` echoes the deleted registration ID — use it to confirm and remove the row from the UI.

---

## Error Responses

| Status | When |
|---|---|
| `400 Bad Request` | `id` is not a valid integer. |
| `401 / 403` | Missing/invalid token, or caller lacks an allowed role. |
| `404 Not Found` | No active registration with that ID (already deleted registrations are treated as not found). |
| `500 Internal Server Error` | Delete failed (`PROGRAM_REGISTRATION_DELETE_FAILED`). |

Error envelope:

```jsonc
{
  "statusCode": 404,
  "message": "<error message>"
}
```

---

## Behaviour & side effects

- Sets `deletedAt = now` and records `updatedBy` = the acting user. The record is preserved (recoverable), not hard-deleted.
- **Seat release:** if the registration actually held a seat (`seatAllocated = true`), the seat count is decremented for its program/session — and for the allocated program/session too, if different. Registrations that never held a seat release nothing.
- **Idempotency:** a second delete on the same ID returns `404` (the first call already cleared `deletedAt IS NULL`).
- Runs inside a DB transaction — seat release and the soft-delete commit together or roll back together.

> **Soft delete vs. Archive:** this endpoint (`DELETE /registration/:id`) sets `deletedAt` and removes the registration from all listings. *Archiving* (`PUT /registration/archive`) is different — it keeps the row visible with `registrationStatus = archived`. Pick delete to make a registration disappear; pick archive to retire it while keeping it listed.

---

## Example

```bash
curl -X DELETE 'https://<host>/registration/101' \
  -H 'Authorization: Bearer <token>'
```

```jsonc
// 200 OK
{
  "statusCode": 200,
  "message": "Program registration deleted successfully",
  "data": { "id": 101 }
}
```
