# One Click Audit — Workflow

Every audit request in Class moves through a **state machine**. Every request the provider sends to Class must declare which state (`RequestStatus`) the audit should transition to.

State transitions are strictly one-way — the status can never move backwards. Once an audit reaches a **final state**, no further updates are accepted.

## The five states

There are 5 states in total. Not all of them can be triggered by the provider.

| State        | Owned by | Meaning | Final? |
|  --- | --- | --- | --- |
| `Pending` | Class | Class has sent the audit request to the provider and is waiting for the user to complete any provisioning / acceptance process with the provider. | No |
| `Requested` | Provider | The provider has acknowledged the audit request. Progress updates and audit documents can be sent while in this state. | No |
| `Processed` | Provider | The audit has been completed. `AuditCertificate` and `CompletedDateTime` must have been provided. | **Yes** |
| `Errorred` | Provider | Something has gone wrong on the provider's end. The provider must supply an `ErrorMessage`. Note the double-`r` spelling — this is intentional. | No |
| `Cancelled` | Class | The Class user has cancelled the audit request. Class notifies the provider using the Cancel outbound request. | **Yes** |


> **Important:** `Pending` and `Cancelled` are Class-owned states. Providers **cannot** submit these as a `RequestStatus`. Providers can only submit `Requested`, `Processed`, or `Errorred`.


## Allowed transitions

| From state | Allowed target states |
|  --- | --- |
| `Pending` | `Requested`, `Errorred`, `Cancelled` |
| `Requested` | `Requested`, `Processed`, `Errorred`, `Cancelled` |
| `Errorred` | `Cancelled` |
| `Processed` | *(final — no further transitions)* |
| `Cancelled` | *(final — no further transitions)* |


Notes:

- `Requested → Requested` is allowed. Providers can post multiple `Requested` updates to send progress messages and additional documents.
- Once in `Errorred`, the only forward transition is `Cancelled` (which is Class-owned).
- `Processed` and `Cancelled` are final states — nothing further can happen once reached.
- The Class user can cancel from `Pending`, `Requested`, or `Errorred` directly.


## Provider request rules per state

| Field           | Requested | Processed | Errorred |
|  --- | --- | --- | --- |
| `MessageData` | Required if `FileData` not supplied | Must be `null` | Must be `null` |
| `FileData` | Required if `MessageData` not supplied | Optional (but `AuditCertificate` must have been received at least once) | Must be `null` |
| `CompletionData` | Must be `null` | Required | Must be `null` |
| `ErrorData` | Must be `null` | Must be `null` | Required |


### Requested rules

- **At least one of** `MessageData` or `FileData` must be populated. Both is fine.
- Class stores at most 3 documents (one of each `FileType`). Sending the same `FileType` again overwrites the previous file.
- Only the **last** `Message` is displayed to the Class user.
- Providers can send `Requested` as many times as needed.


### Processed rules

- `CompletionData.CompletedDateTime` is mandatory.
- The `AuditCertificate` file must exist in Class before the audit can be marked `Processed`. This can be achieved either by sending it earlier in a `Requested` update, or by including it in the `Processed` request's `FileData`.
- `MessageData` and `ErrorData` must be `null`.


### Errorred rules

- `ErrorData.ErrorMessage` is mandatory.
- `MessageData`, `FileData`, and `CompletionData` must all be `null`.
- The error message will be displayed to the Class user, who will be given the option to cancel.


## Cancellation

Cancellation is initiated by the Class user, not the provider. When a Class user cancels an in-progress audit, **Class** POSTs a Cancel request to the provider's registered endpoint (see the Class-to-Provider Requests guide). The provider is not required to acknowledge this via a `Cancelled` status — Class already knows the audit is cancelled.

## File type enumeration

The following `FileType` values are supported when submitting `FileData`:

| Value | Description |
|  --- | --- |
| `AuditCertificate` | The formal Audit Certificate PDF. Required for `Processed`. |
| `AuditContraventionReport` | The Audit Contravention Report PDF (if applicable). |
| `AuditManagementLetter` | The Audit Management Letter PDF (if applicable). |