{
  "openapi": "3.1.0",
  "info": {
    "title": "Vidima IQ API",
    "version": "2026-09-01",
    "summary": "Accounts, contacts, assessors, engagements, assessments, decisions, imports and webhooks for CRM integration.",
    "description": "## Authentication\nEvery request carries an API key: `Authorization: Bearer atk_live_…`. Keys belong to a tenant (an agency or an account) and carry scopes: `read`, `write`, `imports`, `webhooks`, `admin`. Create keys in the app under Settings, Integrations.\n\n**Demo keys** (this environment only): agency `atk_demo_north_audit_agency_key_0001`, account `atk_demo_wattle_grove_account_key_01`.\n\n## Conventions\n- JSON everywhere; camelCase fields; dates are `YYYY-MM-DD`, timestamps ISO 8601 UTC.\n- Lists return `{ data, pagination: { nextCursor, total } }`; pass `cursor` to page.\n- Errors are RFC 9457 problem details (`application/problem+json`).\n- Writes are idempotent: include `source` + `externalId` (your CRM's id) or an `Idempotency-Key` header.\n- Versioning by date in `vidima-api-version`; breaking changes get a new date.\n\n## Webhooks\nSubscribe a URL to events. Each delivery is signed: `Vidima-Signature: t=<unix>,v1=<hex>` where `v1 = HMAC_SHA256(secret, t + \".\" + rawBody)`. Reject if `|now - t| > 300s`. Retries: 1m, 5m, 30m, 2h, 12h. Use `Idempotency-Key` (the event id) to de-duplicate.\n\n```js\n// Node verification example\nconst crypto = require('crypto');\nfunction verify(secret, header, rawBody) {\n  const { t, v1 } = Object.fromEntries(header.split(',').map(p => p.split('=')));\n  const expected = crypto.createHmac('sha256', secret).update(t + '.' + rawBody).digest('hex');\n  return Math.abs(Date.now()/1000 - Number(t)) < 300 && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1));\n}\n```\n\n## Single sign-on\nAdmins configure SAML 2.0 or OIDC providers per tenant (`/sso-providers`). End users are routed by email domain: `GET /api/auth/sso/discover?email=` then `GET /api/auth/sso/start?provider=`. OIDC uses authorisation code + PKCE and verifies the ID token against the provider JWKS; SAML SP metadata is at `/api/auth/sso/saml/{tenantSlug}/metadata` and the ACS at `/api/auth/sso/saml/{tenantSlug}/acs`. Groups map to roles; unknown people can be provisioned just-in-time.\n\n## Migration recipe\n1. `POST /imports` accounts (dry run) from your CRM export, fix mapping until `invalid: 0`, commit with `dryRun: false`.\n2. Import contacts and assessors the same way (`accountExternalId` links contacts to accounts).\n3. Import historical decisions; they appear in account history and feed conflict-of-interest rotation.\n4. Create a webhook for `assessment.submitted` and `decision.recorded` pointing at your CRM (Power Automate, HubSpot workflow, Zapier).\n5. Keep CRM as source of truth for accounts and contacts by upserting with `source` + `externalId` on change."
  },
  "servers": [
    {
      "url": "https://demo.vidimaiq.com/api/v1",
      "description": "Demo environment (example data, demo keys)"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Auth"
    },
    {
      "name": "Custom fields",
      "description": "Fields this tenant adds to its records. Values are sent in each record's custom object. key and type cannot change once created; set active false to archive a field."
    },
    {
      "name": "Credential requirements",
      "description": "What the agency requires of its assessors: training, registrations and checks, and the programs (pack ids, prefixes such as au-racgp-*, or * for all) each is required for. Assignment is blocked when a required credential is missing, expired, rejected or unverified. key never changes once created."
    },
    {
      "name": "Assessor credentials",
      "description": "A credential an assessor holds (certificate, registration, screening check). Assessors upload their own in the app; use this to read the register or bring credentials across from another system, with status verified when your records already prove them."
    },
    {
      "name": "Accounts",
      "description": "The entities an agency accredits: practices, homes, providers. Create or upsert them from your CRM; Vidima IQ never invents accounts."
    },
    {
      "name": "Contacts",
      "description": "People at an account known to the agency. Linking a contact to a login happens when they accept an invitation."
    },
    {
      "name": "Assessors",
      "description": "The agency's assessor roster with credentials (used for eligibility and conflict-of-interest checks)."
    },
    {
      "name": "Engagements",
      "description": "An accreditation cycle between the agency and an account against one pack and profile."
    },
    {
      "name": "Assessments",
      "description": "Self, external or mock assessments. Ratings and evidence live in the event log; this resource exposes status, readiness and team."
    },
    {
      "name": "Findings",
      "description": "Findings raised by assessors, read-only through the API (raised from the assessor workspace)."
    },
    {
      "name": "Actions",
      "description": "Corrective actions. CRMs typically read these to create tasks, or update status when closed elsewhere."
    },
    {
      "name": "Decisions",
      "description": "Accreditation decisions for assessments run in Vidima IQ."
    },
    {
      "name": "Historical decisions",
      "description": "Decisions made before Vidima IQ, imported from the agency's previous system. They appear in the account's history and register and feed conflict-of-interest rotation rules."
    },
    {
      "name": "Sites",
      "description": "Physical locations of an account (practice rooms, clinics, homes, imaging sites). Engagements can cover one or more sites; address changes raise a change notification to the agency."
    },
    {
      "name": "Invitations",
      "description": "Invite a person to a tenant with a role. Accepting the emailed link creates the membership; invitations expire after 14 days and can be revoked."
    },
    {
      "name": "Change notifications",
      "description": "Material changes an account makes (address, name, ownership, sites, service types) that its agencies must acknowledge. Created automatically when account or site details change; agencies update status."
    },
    {
      "name": "Members",
      "description": "People with a role at the tenant (memberships). Read-only through the API; add people with invitations, remove with DELETE."
    },
    {
      "name": "Evidences",
      "description": "Documents, photos and records that support ratings. Files live in private object storage; create with POST /evidence/upload-url (returns a signed upload URL), PUT the bytes there, then POST /evidence/{id}/complete. Download with GET /evidence/{id}/download (60-second signed URL). One file links to many elements across packs via /evidence/{id}/links."
    },
    {
      "name": "Evidence links",
      "description": "Which elements (in which packs and assessments) a piece of evidence supports. Create through POST /evidence/{id}/links."
    },
    {
      "name": "Certificates",
      "description": "The certificates register. Each certificate has a cycle (often three years), its own validity window and a time-derived status (current, expiring within 90 days, expired, superseded, withdrawn, suspended). An account holds many over the years and can hold several at once (different standards, programmes or sites). Certificates issued by Vidima IQ are created by POST /documents/certificate; past certificates from a legacy platform are created here with source legacy (attach the scanned PDF via documentId from the evidence upload flow) or imported in bulk with POST /imports entityType certificates."
    },
    {
      "name": "Imports",
      "description": "Migrate data from a previous system or CRM."
    },
    {
      "name": "Webhooks",
      "description": "Push notifications to your CRM when things change."
    },
    {
      "name": "Single sign-on",
      "description": "SAML 2.0 and OpenID Connect providers per tenant; login flow at /api/auth/sso/*."
    },
    {
      "name": "Events",
      "description": "Event catalogue and polling feed."
    }
  ],
  "paths": {
    "/custom-fields": {
      "get": {
        "tags": [
          "Custom fields"
        ],
        "summary": "List custom fields",
        "description": "Fields this tenant adds to its records. Values are sent in each record's custom object. key and type cannot change once created; set active false to archive a field.",
        "operationId": "listCustomfields",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "entity",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by entity"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Customfield"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "entity": "accounts",
                      "key": "region",
                      "label": "Region",
                      "type": "select",
                      "options": [
                        "South East Queensland",
                        "Northern Queensland",
                        "Northern NSW"
                      ],
                      "required": false,
                      "showInReports": true,
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Custom fields"
        ],
        "summary": "Create or upsert a custom field",
        "description": "Creates a custom field. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `custom_field.created`.",
        "operationId": "createCustomfield",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CustomfieldInput"
              },
              "example": {
                "entity": "accounts",
                "key": "region",
                "label": "Region",
                "type": "select",
                "options": [
                  "South East Queensland",
                  "Northern Queensland",
                  "Northern NSW"
                ],
                "required": false,
                "showInReports": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customfield"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/custom-fields/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Custom fields"
        ],
        "summary": "Get a custom field",
        "operationId": "getCustomfield",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customfield"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Custom fields"
        ],
        "summary": "Update a custom field",
        "operationId": "updateCustomfield",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CustomfieldInput"
              },
              "example": {
                "entity": "accounts",
                "key": "region"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Custom fields"
        ],
        "summary": "Delete a custom field (admin scope)",
        "operationId": "deleteCustomfield",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/credential-types": {
      "get": {
        "tags": [
          "Credential requirements"
        ],
        "summary": "List credential requirements",
        "description": "What the agency requires of its assessors: training, registrations and checks, and the programs (pack ids, prefixes such as au-racgp-*, or * for all) each is required for. Assignment is blocked when a required credential is missing, expired, rejected or unverified. key never changes once created.",
        "operationId": "listCredentialrequirements",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "key",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by key"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Credentialrequirement"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "key": "surveyor-training",
                      "label": "Surveyor training",
                      "requiredFor": [
                        "*"
                      ],
                      "validityMonths": 24,
                      "evidenceRequired": true,
                      "verificationRequired": true,
                      "reminderDays": 60,
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Credential requirements"
        ],
        "summary": "Create or upsert a credential requirement",
        "description": "Creates a credential requirement. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `no event`.",
        "operationId": "createCredentialrequirement",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CredentialrequirementInput"
              },
              "example": {
                "key": "surveyor-training",
                "label": "Surveyor training",
                "requiredFor": [
                  "*"
                ],
                "validityMonths": 24,
                "evidenceRequired": true,
                "verificationRequired": true,
                "reminderDays": 60
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Credentialrequirement"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/credential-types/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Credential requirements"
        ],
        "summary": "Get a credential requirement",
        "operationId": "getCredentialrequirement",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Credentialrequirement"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Credential requirements"
        ],
        "summary": "Update a credential requirement",
        "operationId": "updateCredentialrequirement",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CredentialrequirementInput"
              },
              "example": {
                "key": "surveyor-training",
                "label": "Surveyor training"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Credential requirements"
        ],
        "summary": "Delete a credential requirement (admin scope)",
        "operationId": "deleteCredentialrequirement",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessor-credentials": {
      "get": {
        "tags": [
          "Assessor credentials"
        ],
        "summary": "List assessor credentials",
        "description": "A credential an assessor holds (certificate, registration, screening check). Assessors upload their own in the app; use this to read the register or bring credentials across from another system, with status verified when your records already prove them.",
        "operationId": "listAssessorcredentials",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "assessorUserId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by assessorUserId"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by kind"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by source"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Assessorcredential"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "assessorUserId": "u-helen",
                      "assessorName": "Helen Marsh",
                      "kind": "lead-auditor",
                      "reference": "EG-12345",
                      "issuedAt": "2025-06-30",
                      "expiresAt": "2028-06-29",
                      "status": "verified",
                      "source": "qipcrm",
                      "externalId": "CRED-7781",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Assessor credentials"
        ],
        "summary": "Create or upsert a assessor credential",
        "description": "Creates a assessor credential. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `credential.submitted`.",
        "operationId": "createAssessorcredential",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessorcredentialInput"
              },
              "example": {
                "assessorUserId": "u-helen",
                "assessorName": "Helen Marsh",
                "kind": "lead-auditor",
                "reference": "EG-12345",
                "issuedAt": "2025-06-30",
                "expiresAt": "2028-06-29",
                "status": "verified",
                "source": "qipcrm",
                "externalId": "CRED-7781"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessorcredential"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessor-credentials/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Assessor credentials"
        ],
        "summary": "Get a assessor credential",
        "operationId": "getAssessorcredential",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessorcredential"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Assessor credentials"
        ],
        "summary": "Update a assessor credential",
        "operationId": "updateAssessorcredential",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessorcredentialInput"
              },
              "example": {
                "assessorUserId": "u-helen",
                "assessorName": "Helen Marsh"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Assessor credentials"
        ],
        "summary": "Delete a assessor credential (admin scope)",
        "operationId": "deleteAssessorcredential",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/accounts": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "List accounts",
        "description": "The entities an agency accredits: practices, homes, providers. Create or upsert them from your CRM; Vidima IQ never invents accounts.",
        "operationId": "listAccounts",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "sector",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by sector"
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by source"
          },
          {
            "name": "stage",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by stage"
          },
          {
            "name": "stage",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by stage"
          },
          {
            "name": "owner",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by owner"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Account"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "name": "Wattle Grove Aged Care",
                      "abn": "12 345 678 901",
                      "sector": "aged-care",
                      "sites": [
                        {
                          "name": "Wattle Grove Residential",
                          "suburb": "Carseldine",
                          "state": "QLD"
                        }
                      ],
                      "source": "dynamics365",
                      "externalId": "ACC-00042",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Create or upsert a account",
        "description": "Creates a account. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `account.created`.",
        "operationId": "createAccount",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountInput"
              },
              "example": {
                "name": "Wattle Grove Aged Care",
                "abn": "12 345 678 901",
                "sector": "aged-care",
                "sites": [
                  {
                    "name": "Wattle Grove Residential",
                    "suburb": "Carseldine",
                    "state": "QLD"
                  }
                ],
                "source": "dynamics365",
                "externalId": "ACC-00042"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Account"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "Get a account",
        "operationId": "getAccount",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Account"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Accounts"
        ],
        "summary": "Update a account",
        "operationId": "updateAccount",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountInput"
              },
              "example": {
                "name": "Wattle Grove Aged Care",
                "abn": "12 345 678 901"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Accounts"
        ],
        "summary": "Delete a account (admin scope)",
        "operationId": "deleteAccount",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "summary": "List contacts",
        "description": "People at an account known to the agency. Linking a contact to a login happens when they accept an invitation.",
        "operationId": "listContacts",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by source"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Contact"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "name": "Priya Nair",
                      "email": "priya@wattlegrove.example",
                      "roleTitle": "Quality Manager",
                      "isPrimary": true,
                      "source": "dynamics365",
                      "externalId": "CON-9001",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Contacts"
        ],
        "summary": "Create or upsert a contact",
        "description": "Creates a contact. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `contact.created`.",
        "operationId": "createContact",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "name": "Priya Nair",
                "email": "priya@wattlegrove.example",
                "roleTitle": "Quality Manager",
                "isPrimary": true,
                "source": "dynamics365",
                "externalId": "CON-9001"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Contact"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/contacts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Contacts"
        ],
        "summary": "Get a contact",
        "operationId": "getContact",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Contacts"
        ],
        "summary": "Update a contact",
        "operationId": "updateContact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "name": "Priya Nair"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Contacts"
        ],
        "summary": "Delete a contact (admin scope)",
        "operationId": "deleteContact",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessors": {
      "get": {
        "tags": [
          "Assessors"
        ],
        "summary": "List assessors",
        "description": "The agency's assessor roster with credentials (used for eligibility and conflict-of-interest checks).",
        "operationId": "listAssessors",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by source"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Assessor"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "name": "Helen Marsh",
                      "email": "helen@northaudit.example",
                      "role": "lead",
                      "credentials": [
                        {
                          "kind": "lead-auditor-iso19011",
                          "expiresAt": "2027-06-30"
                        }
                      ],
                      "source": "legacy-access-db",
                      "externalId": "ASR-12",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Assessors"
        ],
        "summary": "Create or upsert a assessor",
        "description": "Creates a assessor. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `assessor.created`.",
        "operationId": "createAssessor",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessorInput"
              },
              "example": {
                "name": "Helen Marsh",
                "email": "helen@northaudit.example",
                "role": "lead",
                "credentials": [
                  {
                    "kind": "lead-auditor-iso19011",
                    "expiresAt": "2027-06-30"
                  }
                ],
                "source": "legacy-access-db",
                "externalId": "ASR-12"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessor"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessors/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Assessors"
        ],
        "summary": "Get a assessor",
        "operationId": "getAssessor",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessor"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Assessors"
        ],
        "summary": "Update a assessor",
        "operationId": "updateAssessor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessorInput"
              },
              "example": {
                "name": "Helen Marsh",
                "email": "helen@northaudit.example"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Assessors"
        ],
        "summary": "Delete a assessor (admin scope)",
        "operationId": "deleteAssessor",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/engagements": {
      "get": {
        "tags": [
          "Engagements"
        ],
        "summary": "List engagements",
        "description": "An accreditation cycle between the agency and an account against one pack and profile.",
        "operationId": "listEngagements",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Engagement"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "packId": "au-aged-care-strengthened",
                      "profileId": "cat6",
                      "cycleLabel": "Re-accreditation 2026",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Engagements"
        ],
        "summary": "Create or upsert a engagement",
        "description": "Creates a engagement. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `engagement.created`.",
        "operationId": "createEngagement",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EngagementInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "packId": "au-aged-care-strengthened",
                "profileId": "cat6",
                "cycleLabel": "Re-accreditation 2026"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Engagement"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/engagements/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Engagements"
        ],
        "summary": "Get a engagement",
        "operationId": "getEngagement",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Engagement"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Engagements"
        ],
        "summary": "Update a engagement",
        "operationId": "updateEngagement",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EngagementInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "packId": "au-aged-care-strengthened"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Engagements"
        ],
        "summary": "Delete a engagement (admin scope)",
        "operationId": "deleteEngagement",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessments": {
      "get": {
        "tags": [
          "Assessments"
        ],
        "summary": "List assessments",
        "description": "Self, external or mock assessments. Ratings and evidence live in the event log; this resource exposes status, readiness and team.",
        "operationId": "listAssessments",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "engagementId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by engagementId"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by kind"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Assessment"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "engagementId": "00000000-0000-0000-0000-000000000010",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "kind": "external",
                      "title": "Site audit: Wattle Grove Residential",
                      "scheduledFrom": "2026-10-22",
                      "team": [
                        "u-helen"
                      ],
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Assessments"
        ],
        "summary": "Create or upsert a assessment",
        "description": "Creates a assessment. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `assessment.created`.",
        "operationId": "createAssessment",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessmentInput"
              },
              "example": {
                "engagementId": "00000000-0000-0000-0000-000000000010",
                "accountId": "00000000-0000-0000-0000-000000000003",
                "kind": "external",
                "title": "Site audit: Wattle Grove Residential",
                "scheduledFrom": "2026-10-22",
                "team": [
                  "u-helen"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessment"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/assessments/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Assessments"
        ],
        "summary": "Get a assessment",
        "operationId": "getAssessment",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Assessment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Assessments"
        ],
        "summary": "Update a assessment",
        "operationId": "updateAssessment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssessmentInput"
              },
              "example": {
                "engagementId": "00000000-0000-0000-0000-000000000010",
                "accountId": "00000000-0000-0000-0000-000000000003"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Assessments"
        ],
        "summary": "Delete a assessment (admin scope)",
        "operationId": "deleteAssessment",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/findings": {
      "get": {
        "tags": [
          "Findings"
        ],
        "summary": "List findings",
        "description": "Findings raised by assessors, read-only through the API (raised from the assessor workspace).",
        "operationId": "listFindings",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "assessmentId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by assessmentId"
          },
          {
            "name": "severity",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by severity"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Finding"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "assessmentId": "demo-aged-1",
                      "elementId": "1.1",
                      "severity": "minor",
                      "statement": "Two of three sampled care plans had no documented personal goals",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/findings/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Findings"
        ],
        "summary": "Get a finding",
        "operationId": "getFinding",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Finding"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Findings"
        ],
        "summary": "Delete a finding (admin scope)",
        "operationId": "deleteFinding",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/actions": {
      "get": {
        "tags": [
          "Actions"
        ],
        "summary": "List actions",
        "description": "Corrective actions. CRMs typically read these to create tasks, or update status when closed elsewhere.",
        "operationId": "listActions",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "assessmentId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by assessmentId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Action"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "assessmentId": "demo-aged-self",
                      "elementId": "2.8",
                      "title": "Publish care-minutes roster and RN coverage plan for Q4",
                      "dueOn": "2026-11-30",
                      "status": "open",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Actions"
        ],
        "summary": "Create or upsert a action",
        "description": "Creates a action. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `action.created`.",
        "operationId": "createAction",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ActionInput"
              },
              "example": {
                "assessmentId": "demo-aged-self",
                "elementId": "2.8",
                "title": "Publish care-minutes roster and RN coverage plan for Q4",
                "dueOn": "2026-11-30",
                "status": "open"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Action"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/actions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Actions"
        ],
        "summary": "Get a action",
        "operationId": "getAction",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Action"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Actions"
        ],
        "summary": "Update a action",
        "operationId": "updateAction",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ActionInput"
              },
              "example": {
                "assessmentId": "demo-aged-self",
                "elementId": "2.8"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Actions"
        ],
        "summary": "Delete a action (admin scope)",
        "operationId": "deleteAction",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/decisions": {
      "get": {
        "tags": [
          "Decisions"
        ],
        "summary": "List decisions",
        "description": "Accreditation decisions for assessments run in Vidima IQ.",
        "operationId": "listDecisions",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "assessmentId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by assessmentId"
          },
          {
            "name": "outcome",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by outcome"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Decision"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "assessmentId": "demo-aged-1",
                      "outcome": "accredited",
                      "certificateNumber": "NAP-2026-0212",
                      "validFrom": "2026-11-14",
                      "validTo": "2029-11-13",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Decisions"
        ],
        "summary": "Create or upsert a decision",
        "description": "Creates a decision. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `decision.recorded`.",
        "operationId": "createDecision",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecisionInput"
              },
              "example": {
                "assessmentId": "demo-aged-1",
                "outcome": "accredited",
                "certificateNumber": "NAP-2026-0212",
                "validFrom": "2026-11-14",
                "validTo": "2029-11-13"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Decision"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/decisions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Decisions"
        ],
        "summary": "Get a decision",
        "operationId": "getDecision",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Decision"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Decisions"
        ],
        "summary": "Update a decision",
        "operationId": "updateDecision",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DecisionInput"
              },
              "example": {
                "assessmentId": "demo-aged-1",
                "outcome": "accredited"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Decisions"
        ],
        "summary": "Delete a decision (admin scope)",
        "operationId": "deleteDecision",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/historical-decisions": {
      "get": {
        "tags": [
          "Historical decisions"
        ],
        "summary": "List historical decisions",
        "description": "Decisions made before Vidima IQ, imported from the agency's previous system. They appear in the account's history and register and feed conflict-of-interest rotation rules.",
        "operationId": "listHistoricaldecisions",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "outcome",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by outcome"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Historicaldecision"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "programme": "Aged Care Quality Standards (2019 edition)",
                      "outcome": "accredited",
                      "certificateNumber": "NAP-2023-0187",
                      "decidedOn": "2023-11-14",
                      "validFrom": "2023-11-14",
                      "validTo": "2026-11-13",
                      "assessors": [
                        "ASR-12"
                      ],
                      "source": "legacy-access-db",
                      "externalId": "DEC-2023-0187",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Historical decisions"
        ],
        "summary": "Create or upsert a historical decision",
        "description": "Creates a historical decision. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `historical_decision.imported`.",
        "operationId": "createHistoricaldecision",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HistoricaldecisionInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "programme": "Aged Care Quality Standards (2019 edition)",
                "outcome": "accredited",
                "certificateNumber": "NAP-2023-0187",
                "decidedOn": "2023-11-14",
                "validFrom": "2023-11-14",
                "validTo": "2026-11-13",
                "assessors": [
                  "ASR-12"
                ],
                "source": "legacy-access-db",
                "externalId": "DEC-2023-0187"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Historicaldecision"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/historical-decisions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Historical decisions"
        ],
        "summary": "Get a historical decision",
        "operationId": "getHistoricaldecision",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Historicaldecision"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Historical decisions"
        ],
        "summary": "Update a historical decision",
        "operationId": "updateHistoricaldecision",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HistoricaldecisionInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "programme": "Aged Care Quality Standards (2019 edition)"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Historical decisions"
        ],
        "summary": "Delete a historical decision (admin scope)",
        "operationId": "deleteHistoricaldecision",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/sites": {
      "get": {
        "tags": [
          "Sites"
        ],
        "summary": "List sites",
        "description": "Physical locations of an account (practice rooms, clinics, homes, imaging sites). Engagements can cover one or more sites; address changes raise a change notification to the agency.",
        "operationId": "listSites",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by kind"
          },
          {
            "name": "active",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by active"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Site"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "name": "Wattle Grove Residential",
                      "kind": "residential",
                      "address": {
                        "line1": "14 Wattle St",
                        "suburb": "Carseldine",
                        "state": "QLD",
                        "postcode": "4034"
                      },
                      "serviceTypes": [
                        "residential-aged-care"
                      ],
                      "isPrimary": true,
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Sites"
        ],
        "summary": "Create or upsert a site",
        "description": "Creates a site. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `site.created`.",
        "operationId": "createSite",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SiteInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "name": "Wattle Grove Residential",
                "kind": "residential",
                "address": {
                  "line1": "14 Wattle St",
                  "suburb": "Carseldine",
                  "state": "QLD",
                  "postcode": "4034"
                },
                "serviceTypes": [
                  "residential-aged-care"
                ],
                "isPrimary": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Site"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/sites/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Sites"
        ],
        "summary": "Get a site",
        "operationId": "getSite",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Site"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Sites"
        ],
        "summary": "Update a site",
        "operationId": "updateSite",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SiteInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "name": "Wattle Grove Residential"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Sites"
        ],
        "summary": "Delete a site (admin scope)",
        "operationId": "deleteSite",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/invitations": {
      "get": {
        "tags": [
          "Invitations"
        ],
        "summary": "List invitations",
        "description": "Invite a person to a tenant with a role. Accepting the emailed link creates the membership; invitations expire after 14 days and can be revoked.",
        "operationId": "listInvitations",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by email"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Invitation"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "email": "new.manager@wattlegrove.example",
                      "role": "account_contributor",
                      "message": "Please help with the clinical care standard.",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Invitations"
        ],
        "summary": "Create or upsert a invitation",
        "description": "Creates a invitation. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `invitation.sent`.",
        "operationId": "createInvitation",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvitationInput"
              },
              "example": {
                "email": "new.manager@wattlegrove.example",
                "role": "account_contributor",
                "message": "Please help with the clinical care standard."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Invitation"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/invitations/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Invitations"
        ],
        "summary": "Get a invitation",
        "operationId": "getInvitation",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Invitation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Invitations"
        ],
        "summary": "Update a invitation",
        "operationId": "updateInvitation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvitationInput"
              },
              "example": {
                "email": "new.manager@wattlegrove.example",
                "role": "account_contributor"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Invitations"
        ],
        "summary": "Delete a invitation (admin scope)",
        "operationId": "deleteInvitation",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/change-requests": {
      "get": {
        "tags": [
          "Change notifications"
        ],
        "summary": "List change notifications",
        "description": "Material changes an account makes (address, name, ownership, sites, service types) that its agencies must acknowledge. Created automatically when account or site details change; agencies update status.",
        "operationId": "listChangenotifications",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by kind"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Changenotification"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "kind": "address",
                      "entityType": "site",
                      "after": {
                        "line1": "16 Wattle St",
                        "suburb": "Carseldine",
                        "state": "QLD",
                        "postcode": "4034"
                      },
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Change notifications"
        ],
        "summary": "Create or upsert a change notification",
        "description": "Creates a change notification. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `account.change_submitted`.",
        "operationId": "createChangenotification",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangenotificationInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "kind": "address",
                "entityType": "site",
                "after": {
                  "line1": "16 Wattle St",
                  "suburb": "Carseldine",
                  "state": "QLD",
                  "postcode": "4034"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Changenotification"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/change-requests/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Change notifications"
        ],
        "summary": "Get a change notification",
        "operationId": "getChangenotification",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Changenotification"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Change notifications"
        ],
        "summary": "Update a change notification",
        "operationId": "updateChangenotification",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangenotificationInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "kind": "address"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Change notifications"
        ],
        "summary": "Delete a change notification (admin scope)",
        "operationId": "deleteChangenotification",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/members": {
      "get": {
        "tags": [
          "Members"
        ],
        "summary": "List members",
        "description": "People with a role at the tenant (memberships). Read-only through the API; add people with invitations, remove with DELETE.",
        "operationId": "listMembers",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "role",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by role"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Member"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "userId": "u-priya",
                      "name": "Priya Nair",
                      "email": "priya@wattlegrove.example",
                      "role": "account_admin",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/members/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Members"
        ],
        "summary": "Get a member",
        "operationId": "getMember",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Member"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Members"
        ],
        "summary": "Delete a member (admin scope)",
        "operationId": "deleteMember",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence": {
      "get": {
        "tags": [
          "Evidences"
        ],
        "summary": "List evidences",
        "description": "Documents, photos and records that support ratings. Files live in private object storage; create with POST /evidence/upload-url (returns a signed upload URL), PUT the bytes there, then POST /evidence/{id}/complete. Download with GET /evidence/{id}/download (60-second signed URL). One file links to many elements across packs via /evidence/{id}/links.",
        "operationId": "listEvidences",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "sha256",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by sha256"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by kind"
          },
          {
            "name": "documentType",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by documentType"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Evidence"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "title": "Infection prevention and control policy v4",
                      "mimeType": "application/pdf",
                      "sizeBytes": 482113,
                      "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                      "version": 4,
                      "status": "stored",
                      "scanStatus": "clean",
                      "approvedOn": "2026-07-01",
                      "reviewDueOn": "2027-07-01",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Evidences"
        ],
        "summary": "Get a evidence",
        "operationId": "getEvidence",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Evidence"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Evidences"
        ],
        "summary": "Delete a evidence (admin scope)",
        "operationId": "deleteEvidence",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence-links": {
      "get": {
        "tags": [
          "Evidence links"
        ],
        "summary": "List evidence links",
        "description": "Which elements (in which packs and assessments) a piece of evidence supports. Create through POST /evidence/{id}/links.",
        "operationId": "listEvidencelinks",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "evidenceId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by evidenceId"
          },
          {
            "name": "assessmentId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by assessmentId"
          },
          {
            "name": "packId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by packId"
          },
          {
            "name": "elementId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by elementId"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Evidencelink"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "evidenceId": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "packId": "au-aged-care-strengthened",
                      "elementId": "4.2",
                      "via": "manual",
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence-links/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Evidence links"
        ],
        "summary": "Get a evidence link",
        "operationId": "getEvidencelink",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Evidencelink"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Evidence links"
        ],
        "summary": "Delete a evidence link (admin scope)",
        "operationId": "deleteEvidencelink",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/certificates": {
      "get": {
        "tags": [
          "Certificates"
        ],
        "summary": "List certificates",
        "description": "The certificates register. Each certificate has a cycle (often three years), its own validity window and a time-derived status (current, expiring within 90 days, expired, superseded, withdrawn, suspended). An account holds many over the years and can hold several at once (different standards, programmes or sites). Certificates issued by Vidima IQ are created by POST /documents/certificate; past certificates from a legacy platform are created here with source legacy (attach the scanned PDF via documentId from the evidence upload flow) or imported in bulk with POST /imports entityType certificates.",
        "operationId": "listCertificates",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from pagination.nextCursor"
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by accountId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by status"
          },
          {
            "name": "programme",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by programme"
          },
          {
            "name": "outcome",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by outcome"
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by source"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Certificate"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "nextCursor": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "tenantId": "00000000-0000-0000-0000-000000000002",
                      "accountId": "00000000-0000-0000-0000-000000000003",
                      "programme": "Aged Care Quality Standards (2019 edition)",
                      "certificateNumber": "NAP-2023-0187",
                      "outcome": "accredited",
                      "decidedOn": "2023-11-14",
                      "cycleStart": "2023-11-14",
                      "cycleEnd": "2026-11-13",
                      "cycleLabel": "2023-2026 cycle",
                      "validFrom": "2023-11-14",
                      "validTo": "2026-11-13",
                      "source": "legacy",
                      "externalId": "CERT-0187",
                      "legacy": {
                        "system": "AccreditationPro",
                        "recordId": "CERT-0187"
                      },
                      "createdAt": "2026-09-13T02:00:00Z",
                      "updatedAt": "2026-09-13T02:00:00Z"
                    }
                  ],
                  "pagination": {
                    "nextCursor": null,
                    "total": 1
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Certificates"
        ],
        "summary": "Create or upsert a certificate",
        "description": "Creates a certificate. If `source` and `externalId` are present and already known for this tenant, the existing record is updated instead (idempotent CRM sync). An `Idempotency-Key` header gives the same guarantee for records without external ids. Emits `certificate.issued`.",
        "operationId": "createCertificate",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CertificateInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "programme": "Aged Care Quality Standards (2019 edition)",
                "certificateNumber": "NAP-2023-0187",
                "outcome": "accredited",
                "decidedOn": "2023-11-14",
                "cycleStart": "2023-11-14",
                "cycleEnd": "2026-11-13",
                "cycleLabel": "2023-2026 cycle",
                "validFrom": "2023-11-14",
                "validTo": "2026-11-13",
                "source": "legacy",
                "externalId": "CERT-0187",
                "legacy": {
                  "system": "AccreditationPro",
                  "recordId": "CERT-0187"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated existing record matched by source + externalId"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Certificate"
                    },
                    "upserted": {
                      "type": "string",
                      "enum": [
                        "created",
                        "updated",
                        "replayed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/certificates/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Certificates"
        ],
        "summary": "Get a certificate",
        "operationId": "getCertificate",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Certificate"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Certificates"
        ],
        "summary": "Update a certificate",
        "operationId": "updateCertificate",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CertificateInput"
              },
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "programme": "Aged Care Quality Standards (2019 edition)"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Certificates"
        ],
        "summary": "Delete a certificate (admin scope)",
        "operationId": "deleteCertificate",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence/upload-url": {
      "post": {
        "tags": [
          "Evidences"
        ],
        "summary": "Start an upload",
        "description": "Step 1 of 2. Returns the evidence record and a signed upload URL (valid 2 hours). PUT the raw bytes to `upload.url` with `upload.headers`, then call `/evidence/{id}/complete`. Bytes go straight to object storage, so there is no size limit on this API (250 MB per object).",
        "operationId": "startUpload",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UploadRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Same content already stored; no upload needed"
          },
          "201": {
            "description": "Upload URL issued",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "evidence": {
                      "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
                      "status": "pending",
                      "version": 1
                    },
                    "deduplicated": false,
                    "upload": {
                      "method": "PUT",
                      "url": "https://xyz.supabase.co/storage/v1/object/upload/sign/evidence/…?token=…",
                      "headers": {
                        "content-type": "application/pdf",
                        "x-upsert": "false"
                      },
                      "expiresInSeconds": 7200
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "File type not accepted"
          }
        }
      }
    },
    "/evidence/{id}/complete": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "tags": [
          "Evidences"
        ],
        "summary": "Finish an upload",
        "description": "Step 2 of 2. Confirms the object exists, records size and hash, marks the evidence stored and emits `evidence.stored`. Virus scanning runs asynchronously (`scanStatus`).",
        "operationId": "completeUpload",
        "responses": {
          "200": {
            "description": "Stored"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "Bytes not uploaded yet"
          }
        }
      }
    },
    "/evidence/{id}/download": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "redirect",
          "in": "query",
          "schema": {
            "type": "string",
            "enum": [
              "true",
              "false"
            ],
            "default": "true"
          },
          "description": "false returns the signed URL as JSON instead of a 302"
        }
      ],
      "get": {
        "tags": [
          "Evidences"
        ],
        "summary": "Download (signed URL, 60 s)",
        "operationId": "downloadEvidence",
        "responses": {
          "200": {
            "description": "Signed URL as JSON",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "url": "https://…",
                    "expiresInSeconds": 60
                  }
                }
              }
            }
          },
          "302": {
            "description": "Redirect to a signed URL"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/evidence/{id}/links": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Evidences"
        ],
        "summary": "Elements this evidence supports",
        "operationId": "listEvidenceLinks",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Evidences"
        ],
        "summary": "Link evidence to elements",
        "description": "Idempotent. One document can support many elements across packs; crosswalks and AI mapping create links with `via` set accordingly.",
        "operationId": "linkEvidence",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "links": [
                  {
                    "packId": "au-aged-care-strengthened",
                    "elementId": "4.2",
                    "assessmentId": "demo-aged-self"
                  },
                  {
                    "packId": "au-ndis-practice-standards",
                    "elementId": "core.2.6",
                    "via": "crosswalk"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Linked"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/documents/certificate": {
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "Generate an accreditation certificate PDF",
        "description": "Agency scope. Renders a certificate with the agency logo (set under Agency settings), stores it as a generated document (same retention and signed downloads as evidence), records the decision when `assessmentId` is given, and optionally emails it with a congratulations note. Returns the document, the decision and a download URL; the PDF can be re-downloaded or re-sent later.",
        "operationId": "generateCertificate",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "accountId": "00000000-0000-0000-0000-000000000003",
                "packId": "au-aged-care-strengthened",
                "assessmentId": "demo-aged-1",
                "outcome": "accredited",
                "validFrom": "2026-11-14",
                "validTo": "2029-11-13",
                "emailTo": [
                  "priya@wattlegrove.example"
                ],
                "message": "Congratulations to the whole team."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Generated",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "document": {
                      "id": "55bd…",
                      "title": "Certificate NAP-2026-297C: Wattle Grove Aged Care",
                      "documentType": "certificate",
                      "sizeBytes": 3500,
                      "metadata": {
                        "certificateNumber": "NAP-2026-297C",
                        "verificationCode": "F24744630A"
                      }
                    },
                    "decision": {
                      "id": "…",
                      "outcome": "accredited",
                      "certificateNumber": "NAP-2026-297C"
                    },
                    "downloadUrl": "https://…/api/v1/evidence/55bd…/download",
                    "emailed": {
                      "to": [
                        "priya@wattlegrove.example"
                      ],
                      "provider": "resend"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/documents/report": {
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "Generate an assessment report PDF",
        "description": "Agency or account scope. Summary, findings, actions and every element rating with notes and evidence counts, branded with the caller's logo. Send the projection (ratings by element id using the pack's scale codes, notes, findings, actions); with Supabase the server can project from the event log itself. Stored and emailable like a certificate.",
        "operationId": "generateReport",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "assessment": {
                  "id": "demo-aged-1",
                  "title": "Site audit: Wattle Grove Residential",
                  "kind": "external",
                  "status": "submitted",
                  "packId": "au-aged-care-strengthened",
                  "packVersion": "0.1.0",
                  "profileId": "cat6"
                },
                "accountId": "00000000-0000-0000-0000-000000000003",
                "ratings": {
                  "1.1": {
                    "code": "conformant"
                  },
                  "2.5": {
                    "code": "major",
                    "note": "Register not reviewed since March"
                  }
                },
                "findings": [
                  {
                    "id": "f1",
                    "elementId": "2.5",
                    "severity": "major",
                    "statement": "Risk register not reviewed in the required period."
                  }
                ],
                "actions": [
                  {
                    "id": "a1",
                    "elementId": "2.5",
                    "title": "Assign owners to all open risks",
                    "dueOn": "2026-10-30",
                    "status": "open"
                  }
                ],
                "team": [
                  "Helen Marsh (lead)"
                ],
                "emailTo": [
                  "priya@wattlegrove.example"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Generated"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}/email": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "Email a stored document",
        "description": "Sends the PDF as an attachment (up to 20 MB) with an optional subject and message. Certificates with outcome accredited get a congratulations note by default. Emits `document.emailed`.",
        "operationId": "emailDocument",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "to": [
                  "priya@wattlegrove.example",
                  "board@wattlegrove.example"
                ],
                "message": "Attached for the board pack."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sent (or recorded in the demo outbox when no email provider is configured)"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/documents/outbox": {
      "get": {
        "tags": [
          "Documents"
        ],
        "summary": "Demo email outbox",
        "description": "Only populated when no email provider is configured; shows what would have been sent.",
        "operationId": "documentOutbox",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/reports/summary": {
      "get": {
        "tags": [
          "Reports"
        ],
        "summary": "Dashboard summary",
        "description": "Agency scope. Tiles and chart series for accreditation (certificates by status, standard, outcome; expiries in 30/60/90/180 days and by month; assessments; findings; pending client changes) and business development (accounts by stage: prospect, quoted, onboarding, active, lapsed, lost, not involved; open quote value; quotes expiring in 14 days; pipeline value by stage; quotes by owner). Filters narrow the account set.",
        "operationId": "reportSummary",
        "parameters": [
          {
            "name": "sector",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "programme",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "stage",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "owner",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "tiles": {
                      "accounts": 14,
                      "active": 4,
                      "quoted": 3,
                      "quotedValue": 23400,
                      "certificatesCurrent": 2,
                      "certificatesExpiring": 2,
                      "expiring90": 2
                    },
                    "charts": {
                      "certificatesByStatus": [
                        {
                          "label": "current",
                          "value": 2
                        },
                        {
                          "label": "expiring",
                          "value": 2
                        }
                      ],
                      "accountsByStage": [
                        {
                          "label": "quoted",
                          "value": 3
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/reports/{name}": {
      "parameters": [
        {
          "name": "name",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "certificates",
              "expiries",
              "pipeline",
              "quotes",
              "not_involved",
              "accounts",
              "assessments",
              "changes"
            ]
          }
        },
        {
          "name": "status",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "programme",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "sector",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "outcome",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "stage",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "owner",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "accountId",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "kind",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "q",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "from",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "to",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "days",
          "in": "query",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "format",
          "in": "query",
          "schema": {
            "type": "string",
            "enum": [
              "json",
              "csv"
            ]
          },
          "description": "csv returns a downloadable file (also honoured for Accept: text/csv)"
        }
      ],
      "get": {
        "tags": [
          "Reports"
        ],
        "summary": "Named report (JSON or CSV)",
        "description": "Filterable row-level reports: certificates register, coming expiries (`days` horizon, default 180), business development pipeline, open quotes (soonest expiry first), not involved accounts, accounts with certificate count and latest expiry, assessments, client change notifications. Same filters as the summary plus report-specific ones.",
        "operationId": "report",
        "responses": {
          "200": {
            "description": "Rows plus report metadata (columns, description, filters)"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/me": {
      "get": {
        "tags": [
          "Auth"
        ],
        "summary": "Who am I",
        "description": "Returns the tenant and scopes behind the API key. Use it to test a key.",
        "operationId": "me",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "tenantId": "00000000-0000-0000-0000-000000000002",
                    "tenantKind": "agency",
                    "keyName": "North Audit Partners (demo)",
                    "scopes": [
                      "read",
                      "write",
                      "imports",
                      "webhooks",
                      "admin"
                    ],
                    "apiVersion": "2026-09-01"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/imports": {
      "get": {
        "tags": [
          "Imports"
        ],
        "summary": "List import jobs",
        "operationId": "listImports",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "tags": [
          "Imports"
        ],
        "summary": "Run an import (dry-run by default)",
        "operationId": "createImport",
        "description": "Migrate data from a previous system or CRM. Supported entity types: accounts, contacts, assessors, engagements, decisions, certificates. Rows are validated against the resource schema; `accountExternalId` or `accountName` columns resolve `accountId` for child records. Dates accept d/m/Y or ISO. Send JSON rows, or POST raw CSV with `Content-Type: text/csv`, `?entityType=&source=&dryRun=` and the column mapping as JSON in the `X-Vidima-Mapping` header. Records are upserted by (source, externalId), so re-running an import is safe. Emits `import.completed` when committed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImportRequest"
              }
            },
            "text/csv": {
              "schema": {
                "type": "string"
              },
              "example": "Facility ID,Program,Result,Cert No,Decision Date,Expiry,Surveyors,Decision ID\nACC-00042,Aged Care Quality Standards (2019 edition),accredited,NAP-2023-0187,14/11/2023,13/11/2026,ASR-12;ASR-19,DEC-2023-0187"
            }
          }
        },
        "responses": {
          "201": {
            "description": "Job result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ImportJob"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/imports/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Imports"
        ],
        "summary": "Get an import job with row results",
        "operationId": "getImport",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ImportJob"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "List webhook subscriptions",
        "operationId": "listWebhooks",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookSubscription"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Create a webhook subscription",
        "operationId": "createWebhook",
        "description": "Subscribe an https URL to event types (or `*`). The signing secret is returned once. Deliveries are retried at 1m, 5m, 30m, 2h and 12h, then marked dead. Respond 2xx within 10 seconds; do the work asynchronously.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "account.created",
                        "account.change_submitted",
                        "evidence.stored",
                        "certificate.issued",
                        "certificate.expiring",
                        "credential.submitted",
                        "credential.verified",
                        "credential.rejected",
                        "credential.expiring",
                        "document.generated",
                        "report.delivered",
                        "document.emailed",
                        "account.updated",
                        "contact.created",
                        "engagement.created",
                        "assessment.created",
                        "assessment.submitted",
                        "assessment.team_assigned",
                        "finding.raised",
                        "action.created",
                        "action.overdue",
                        "decision.recorded",
                        "certificate.expiring",
                        "import.completed",
                        "*"
                      ]
                    }
                  },
                  "description": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "url": "https://prod-12.australiasoutheast.logic.azure.com/workflows/abc/triggers/manual/paths/invoke",
                "events": [
                  "assessment.submitted",
                  "decision.recorded"
                ],
                "description": "Dynamics 365 via Power Automate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created, includes secret once",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "0b3…",
                    "url": "https://…",
                    "events": [
                      "assessment.submitted"
                    ],
                    "active": true,
                    "secret": "whsec_9f3…"
                  },
                  "note": "Store the secret now; it is not shown again."
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Get a subscription",
        "operationId": "getWebhook",
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Update url, events, description or active",
        "operationId": "updateWebhook",
        "requestBody": {
          "content": {
            "application/json": {
              "example": {
                "active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      },
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Delete a subscription",
        "operationId": "deleteWebhook",
        "responses": {
          "204": {
            "description": "Deleted"
          }
        }
      }
    },
    "/webhooks/{id}/deliveries": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Delivery attempts for a subscription",
        "operationId": "listDeliveries",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Delivery"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Send a test event now",
        "operationId": "testWebhook",
        "requestBody": {
          "content": {
            "application/json": {
              "example": {
                "type": "assessment.submitted"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The delivery attempt result"
          }
        }
      }
    },
    "/sso-providers": {
      "get": {
        "tags": [
          "Single sign-on"
        ],
        "summary": "List identity providers (admin scope)",
        "operationId": "listSsoProviders",
        "parameters": [
          {
            "name": "tenantId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Platform keys only: configure another tenant"
          },
          {
            "name": "presets",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Return the preset catalogue (fields, defaults) instead"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/IdentityProvider"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the required scope",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Single sign-on"
        ],
        "summary": "Add an identity provider",
        "operationId": "createSsoProvider",
        "description": "Create a SAML 2.0 or OpenID Connect provider from a preset (Entra ID, Auth0, Okta, Google, generic). The client secret is encrypted at rest and never returned. Domains listed here route matching email addresses to this provider on the login page. Enable it after pasting the redirect / ACS URLs (from GET /sso-providers/{id}) into the IdP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "preset": "entra-id",
                "name": "North Audit staff (Entra ID)",
                "config": {
                  "tenantId": "11111111-2222-3333-4444-555555555555",
                  "clientId": "a1b2c3d4"
                },
                "clientSecret": "…",
                "domains": [
                  "northaudit.example"
                ],
                "roleMapping": [
                  {
                    "group": "Vidima-Agency-Admins",
                    "role": "agency_admin"
                  },
                  {
                    "group": "Vidima-Assessors",
                    "role": "assessor"
                  }
                ],
                "defaultRole": "assessor",
                "jitProvisioning": true,
                "enabled": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/IdentityProvider"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/sso-providers/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Single sign-on"
        ],
        "summary": "Get a provider with the values to paste into the IdP",
        "operationId": "getSsoProvider",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "id": "idp-demo-entra",
                    "name": "North Audit staff (Entra ID)"
                  },
                  "idpSetup": [
                    {
                      "label": "Redirect URI (web)",
                      "value": "https://app.vidimaiq.example/api/auth/sso/callback/oidc"
                    }
                  ],
                  "startUrl": "https://app.vidimaiq.example/api/auth/sso/start?provider=idp-demo-entra"
                }
              }
            }
          },
          "404": {
            "description": "Not found for this tenant",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Single sign-on"
        ],
        "summary": "Update name, config, domains, roles, enabled, enforce, clientSecret",
        "operationId": "updateSsoProvider",
        "requestBody": {
          "content": {
            "application/json": {
              "example": {
                "enabled": true,
                "enforce": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      },
      "delete": {
        "tags": [
          "Single sign-on"
        ],
        "summary": "Remove a provider",
        "operationId": "deleteSsoProvider",
        "responses": {
          "204": {
            "description": "Deleted"
          }
        }
      }
    },
    "/events": {
      "get": {
        "tags": [
          "Events"
        ],
        "summary": "Recent events for this tenant (polling alternative to webhooks), or the catalogue",
        "operationId": "listEvents",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "catalogue",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Return the event catalogue with example payloads instead"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "type": "account.created",
                      "description": "An account (practice, home, provider) was created or imported for the agency.",
                      "example": {
                        "accountId": "00000000-0000-0000-0000-000000000003",
                        "name": "Wattle Grove Aged Care",
                        "source": "dynamics365",
                        "externalId": "ACC-00042"
                      }
                    },
                    {
                      "type": "account.change_submitted",
                      "description": "An account changed its address, name, ownership, sites or services through self-service; the agency must acknowledge.",
                      "example": {
                        "accountId": "00000000-0000-0000-0000-000000000003",
                        "changeRequestId": "7b1c…",
                        "kind": "address",
                        "after": {
                          "address": {
                            "line1": "16 Wattle St",
                            "suburb": "Carseldine",
                            "state": "QLD",
                            "postcode": "4034"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "atk_live_…"
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "example": {
          "type": "https://vidimaiq.com/errors/validation_failed",
          "title": "validation failed",
          "status": 422,
          "detail": "One or more fields are invalid.",
          "errors": [
            "name is required"
          ]
        }
      },
      "Customfield": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "entity": {
            "type": "string",
            "enum": [
              "accounts",
              "contacts",
              "assessors",
              "engagements",
              "assessments",
              "certificates"
            ],
            "example": "accounts"
          },
          "key": {
            "type": "string",
            "description": "camelCase, letters and digits",
            "example": "region"
          },
          "label": {
            "type": "string",
            "example": "Region"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "longtext",
              "number",
              "currency",
              "date",
              "boolean",
              "select",
              "multiselect",
              "email",
              "url",
              "phone"
            ],
            "example": "select"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Choices for select and multiselect",
            "example": [
              "South East Queensland",
              "Northern Queensland",
              "Northern NSW"
            ]
          },
          "required": {
            "type": "boolean",
            "example": false
          },
          "helpText": {
            "type": "string",
            "example": "Health service region used for board reporting"
          },
          "order": {
            "type": "number",
            "example": 1
          },
          "active": {
            "type": "boolean",
            "example": true
          },
          "showInReports": {
            "type": "boolean",
            "example": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "entity": "accounts",
          "key": "region",
          "label": "Region",
          "type": "select",
          "options": [
            "South East Queensland",
            "Northern Queensland",
            "Northern NSW"
          ],
          "required": false,
          "showInReports": true,
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "CustomfieldInput": {
        "type": "object",
        "required": [
          "entity",
          "key",
          "label",
          "type"
        ],
        "properties": {
          "entity": {
            "type": "string",
            "enum": [
              "accounts",
              "contacts",
              "assessors",
              "engagements",
              "assessments",
              "certificates"
            ],
            "example": "accounts"
          },
          "key": {
            "type": "string",
            "description": "camelCase, letters and digits",
            "example": "region"
          },
          "label": {
            "type": "string",
            "example": "Region"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "longtext",
              "number",
              "currency",
              "date",
              "boolean",
              "select",
              "multiselect",
              "email",
              "url",
              "phone"
            ],
            "example": "select"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Choices for select and multiselect",
            "example": [
              "South East Queensland",
              "Northern Queensland",
              "Northern NSW"
            ]
          },
          "required": {
            "type": "boolean",
            "example": false
          },
          "helpText": {
            "type": "string",
            "example": "Health service region used for board reporting"
          },
          "order": {
            "type": "number",
            "example": 1
          },
          "active": {
            "type": "boolean",
            "example": true
          },
          "showInReports": {
            "type": "boolean",
            "example": true
          }
        },
        "example": {
          "entity": "accounts",
          "key": "region",
          "label": "Region",
          "type": "select",
          "options": [
            "South East Queensland",
            "Northern Queensland",
            "Northern NSW"
          ],
          "required": false,
          "showInReports": true
        }
      },
      "Credentialrequirement": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "key": {
            "type": "string",
            "description": "Lower case letters, numbers and hyphens",
            "example": "surveyor-training"
          },
          "label": {
            "type": "string",
            "example": "Surveyor training"
          },
          "description": {
            "type": "string",
            "example": "Initial course and refresher every two years"
          },
          "requiredFor": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "au-racgp-*"
            },
            "example": [
              "*"
            ]
          },
          "validityMonths": {
            "type": "number",
            "example": 24
          },
          "evidenceRequired": {
            "type": "boolean",
            "example": true
          },
          "verificationRequired": {
            "type": "boolean",
            "example": true
          },
          "reminderDays": {
            "type": "number",
            "example": 60
          },
          "active": {
            "type": "boolean",
            "example": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "key": "surveyor-training",
          "label": "Surveyor training",
          "requiredFor": [
            "*"
          ],
          "validityMonths": 24,
          "evidenceRequired": true,
          "verificationRequired": true,
          "reminderDays": 60,
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "CredentialrequirementInput": {
        "type": "object",
        "required": [
          "key",
          "label"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Lower case letters, numbers and hyphens",
            "example": "surveyor-training"
          },
          "label": {
            "type": "string",
            "example": "Surveyor training"
          },
          "description": {
            "type": "string",
            "example": "Initial course and refresher every two years"
          },
          "requiredFor": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "au-racgp-*"
            },
            "example": [
              "*"
            ]
          },
          "validityMonths": {
            "type": "number",
            "example": 24
          },
          "evidenceRequired": {
            "type": "boolean",
            "example": true
          },
          "verificationRequired": {
            "type": "boolean",
            "example": true
          },
          "reminderDays": {
            "type": "number",
            "example": 60
          },
          "active": {
            "type": "boolean",
            "example": true
          }
        },
        "example": {
          "key": "surveyor-training",
          "label": "Surveyor training",
          "requiredFor": [
            "*"
          ],
          "validityMonths": 24,
          "evidenceRequired": true,
          "verificationRequired": true,
          "reminderDays": 60
        }
      },
      "Assessorcredential": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "assessorUserId": {
            "type": "string",
            "description": "The assessor (user id, or the assessor record id for people without a login)",
            "example": "u-helen"
          },
          "assessorName": {
            "type": "string",
            "example": "Helen Marsh"
          },
          "kind": {
            "type": "string",
            "description": "A credential-types key",
            "example": "surveyor-training"
          },
          "reference": {
            "type": "string",
            "example": "EG-12345"
          },
          "issuedAt": {
            "type": "string",
            "format": "date",
            "example": "2026-03-01"
          },
          "expiresAt": {
            "type": "string",
            "format": "date",
            "example": "2028-02-29"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "verified",
              "rejected"
            ],
            "example": "verified"
          },
          "evidenceId": {
            "type": "string",
            "format": "uuid",
            "description": "Uploaded certificate (see /evidence)"
          },
          "verifiedBy": {
            "type": "string",
            "example": "David Chen"
          },
          "verifiedAt": {
            "type": "string",
            "format": "date-time"
          },
          "note": {
            "type": "string",
            "description": "Reason for a rejection"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "assessorUserId": "u-helen",
          "assessorName": "Helen Marsh",
          "kind": "lead-auditor",
          "reference": "EG-12345",
          "issuedAt": "2025-06-30",
          "expiresAt": "2028-06-29",
          "status": "verified",
          "source": "qipcrm",
          "externalId": "CRED-7781",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "AssessorcredentialInput": {
        "type": "object",
        "required": [
          "assessorUserId",
          "kind"
        ],
        "properties": {
          "assessorUserId": {
            "type": "string",
            "description": "The assessor (user id, or the assessor record id for people without a login)",
            "example": "u-helen"
          },
          "assessorName": {
            "type": "string",
            "example": "Helen Marsh"
          },
          "kind": {
            "type": "string",
            "description": "A credential-types key",
            "example": "surveyor-training"
          },
          "reference": {
            "type": "string",
            "example": "EG-12345"
          },
          "issuedAt": {
            "type": "string",
            "format": "date",
            "example": "2026-03-01"
          },
          "expiresAt": {
            "type": "string",
            "format": "date",
            "example": "2028-02-29"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "verified",
              "rejected"
            ],
            "example": "verified"
          },
          "evidenceId": {
            "type": "string",
            "format": "uuid",
            "description": "Uploaded certificate (see /evidence)"
          },
          "verifiedBy": {
            "type": "string",
            "example": "David Chen"
          },
          "verifiedAt": {
            "type": "string",
            "format": "date-time"
          },
          "note": {
            "type": "string",
            "description": "Reason for a rejection"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "assessorUserId": "u-helen",
          "assessorName": "Helen Marsh",
          "kind": "lead-auditor",
          "reference": "EG-12345",
          "issuedAt": "2025-06-30",
          "expiresAt": "2028-06-29",
          "status": "verified",
          "source": "qipcrm",
          "externalId": "CRED-7781"
        }
      },
      "Account": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "name": {
            "type": "string",
            "example": "Wattle Grove Aged Care"
          },
          "abn": {
            "type": "string",
            "example": "12 345 678 901"
          },
          "sector": {
            "type": "string",
            "enum": [
              "aged-care",
              "ndis",
              "general-practice",
              "hospital",
              "pharmacy",
              "dental",
              "other"
            ],
            "example": "aged-care"
          },
          "sites": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "name": "Wattle Grove Residential",
                "suburb": "Carseldine",
                "state": "QLD"
              }
            },
            "description": "Physical sites or services"
          },
          "stage": {
            "type": "string",
            "enum": [
              "prospect",
              "quoted",
              "onboarding",
              "active",
              "lapsed",
              "lost",
              "not_involved"
            ],
            "description": "Business development stage of this agency's relationship with the account (agency_accounts in Postgres). An active engagement moves it to active.",
            "example": "quoted"
          },
          "owner": {
            "type": "string",
            "description": "BD owner",
            "example": "David Chen"
          },
          "quoteAmount": {
            "type": "number",
            "description": "Quoted fee (AUD)",
            "example": 6800
          },
          "quoteReference": {
            "type": "string",
            "example": "Q-2026-0142"
          },
          "quotedOn": {
            "type": "string",
            "format": "date"
          },
          "quoteExpiresOn": {
            "type": "string",
            "format": "date"
          },
          "expectedCloseOn": {
            "type": "string",
            "format": "date"
          },
          "wonOn": {
            "type": "string",
            "format": "date"
          },
          "lostOn": {
            "type": "string",
            "format": "date"
          },
          "lostReason": {
            "type": "string"
          },
          "nextAction": {
            "type": "string"
          },
          "nextActionOn": {
            "type": "string",
            "format": "date"
          },
          "notes": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "parentId": {
            "type": "string",
            "format": "uuid",
            "description": "Head office / group account this account belongs to (dental chains, hospital groups, imaging networks). Members of the parent inherit access."
          },
          "isGroup": {
            "type": "boolean",
            "description": "True for a head office that has child accounts"
          },
          "details": {
            "type": "object",
            "additionalProperties": true,
            "description": "Self-service details: abn, phone, email, website, address {line1,line2,suburb,state,postcode}, postalAddress",
            "example": {
              "abn": "12 345 678 901",
              "phone": "07 3000 0000",
              "address": {
                "line1": "14 Wattle St",
                "suburb": "Carseldine",
                "state": "QLD",
                "postcode": "4034"
              }
            }
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "name": "Wattle Grove Aged Care",
          "abn": "12 345 678 901",
          "sector": "aged-care",
          "sites": [
            {
              "name": "Wattle Grove Residential",
              "suburb": "Carseldine",
              "state": "QLD"
            }
          ],
          "source": "dynamics365",
          "externalId": "ACC-00042",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "AccountInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "name": {
            "type": "string",
            "example": "Wattle Grove Aged Care"
          },
          "abn": {
            "type": "string",
            "example": "12 345 678 901"
          },
          "sector": {
            "type": "string",
            "enum": [
              "aged-care",
              "ndis",
              "general-practice",
              "hospital",
              "pharmacy",
              "dental",
              "other"
            ],
            "example": "aged-care"
          },
          "sites": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "name": "Wattle Grove Residential",
                "suburb": "Carseldine",
                "state": "QLD"
              }
            },
            "description": "Physical sites or services"
          },
          "stage": {
            "type": "string",
            "enum": [
              "prospect",
              "quoted",
              "onboarding",
              "active",
              "lapsed",
              "lost",
              "not_involved"
            ],
            "description": "Business development stage of this agency's relationship with the account (agency_accounts in Postgres). An active engagement moves it to active.",
            "example": "quoted"
          },
          "owner": {
            "type": "string",
            "description": "BD owner",
            "example": "David Chen"
          },
          "quoteAmount": {
            "type": "number",
            "description": "Quoted fee (AUD)",
            "example": 6800
          },
          "quoteReference": {
            "type": "string",
            "example": "Q-2026-0142"
          },
          "quotedOn": {
            "type": "string",
            "format": "date"
          },
          "quoteExpiresOn": {
            "type": "string",
            "format": "date"
          },
          "expectedCloseOn": {
            "type": "string",
            "format": "date"
          },
          "wonOn": {
            "type": "string",
            "format": "date"
          },
          "lostOn": {
            "type": "string",
            "format": "date"
          },
          "lostReason": {
            "type": "string"
          },
          "nextAction": {
            "type": "string"
          },
          "nextActionOn": {
            "type": "string",
            "format": "date"
          },
          "notes": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "parentId": {
            "type": "string",
            "format": "uuid",
            "description": "Head office / group account this account belongs to (dental chains, hospital groups, imaging networks). Members of the parent inherit access."
          },
          "isGroup": {
            "type": "boolean",
            "description": "True for a head office that has child accounts"
          },
          "details": {
            "type": "object",
            "additionalProperties": true,
            "description": "Self-service details: abn, phone, email, website, address {line1,line2,suburb,state,postcode}, postalAddress",
            "example": {
              "abn": "12 345 678 901",
              "phone": "07 3000 0000",
              "address": {
                "line1": "14 Wattle St",
                "suburb": "Carseldine",
                "state": "QLD",
                "postcode": "4034"
              }
            }
          }
        },
        "example": {
          "name": "Wattle Grove Aged Care",
          "abn": "12 345 678 901",
          "sector": "aged-care",
          "sites": [
            {
              "name": "Wattle Grove Residential",
              "suburb": "Carseldine",
              "state": "QLD"
            }
          ],
          "source": "dynamics365",
          "externalId": "ACC-00042"
        }
      },
      "Contact": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000003"
          },
          "name": {
            "type": "string",
            "example": "Priya Nair"
          },
          "email": {
            "type": "string",
            "example": "priya@wattlegrove.example"
          },
          "phone": {
            "type": "string",
            "example": "+61 7 3000 0000"
          },
          "roleTitle": {
            "type": "string",
            "example": "Quality Manager"
          },
          "isPrimary": {
            "type": "boolean",
            "example": true
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "name": "Priya Nair",
          "email": "priya@wattlegrove.example",
          "roleTitle": "Quality Manager",
          "isPrimary": true,
          "source": "dynamics365",
          "externalId": "CON-9001",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "ContactInput": {
        "type": "object",
        "required": [
          "accountId",
          "name"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000003"
          },
          "name": {
            "type": "string",
            "example": "Priya Nair"
          },
          "email": {
            "type": "string",
            "example": "priya@wattlegrove.example"
          },
          "phone": {
            "type": "string",
            "example": "+61 7 3000 0000"
          },
          "roleTitle": {
            "type": "string",
            "example": "Quality Manager"
          },
          "isPrimary": {
            "type": "boolean",
            "example": true
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "name": "Priya Nair",
          "email": "priya@wattlegrove.example",
          "roleTitle": "Quality Manager",
          "isPrimary": true,
          "source": "dynamics365",
          "externalId": "CON-9001"
        }
      },
      "Assessor": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "name": {
            "type": "string",
            "example": "Helen Marsh"
          },
          "email": {
            "type": "string",
            "example": "helen@northaudit.example"
          },
          "role": {
            "type": "string",
            "enum": [
              "assessor",
              "lead"
            ],
            "example": "assessor"
          },
          "credentials": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "kind": "lead-auditor-iso19011",
                "reference": "EG-12345",
                "expiresAt": "2027-06-30"
              }
            },
            "description": "Credential kinds with expiry, e.g. lead-auditor-iso19011, aged-care-quality-assessor, ndis-module-1, agency-surveyor-training, clinical-registration"
          },
          "pastAssessments": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "DEC-2023-0187"
            },
            "description": "External ids of assessments they served on (for rotation checks after migration)"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "name": "Helen Marsh",
          "email": "helen@northaudit.example",
          "role": "lead",
          "credentials": [
            {
              "kind": "lead-auditor-iso19011",
              "expiresAt": "2027-06-30"
            }
          ],
          "source": "legacy-access-db",
          "externalId": "ASR-12",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "AssessorInput": {
        "type": "object",
        "required": [
          "name",
          "email"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "name": {
            "type": "string",
            "example": "Helen Marsh"
          },
          "email": {
            "type": "string",
            "example": "helen@northaudit.example"
          },
          "role": {
            "type": "string",
            "enum": [
              "assessor",
              "lead"
            ],
            "example": "assessor"
          },
          "credentials": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "kind": "lead-auditor-iso19011",
                "reference": "EG-12345",
                "expiresAt": "2027-06-30"
              }
            },
            "description": "Credential kinds with expiry, e.g. lead-auditor-iso19011, aged-care-quality-assessor, ndis-module-1, agency-surveyor-training, clinical-registration"
          },
          "pastAssessments": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "DEC-2023-0187"
            },
            "description": "External ids of assessments they served on (for rotation checks after migration)"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "name": "Helen Marsh",
          "email": "helen@northaudit.example",
          "role": "lead",
          "credentials": [
            {
              "kind": "lead-auditor-iso19011",
              "expiresAt": "2027-06-30"
            }
          ],
          "source": "legacy-access-db",
          "externalId": "ASR-12"
        }
      },
      "Engagement": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000003"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "packVersion": {
            "type": "string",
            "example": "0.1.0"
          },
          "profileId": {
            "type": "string",
            "example": "cat6"
          },
          "cycleLabel": {
            "type": "string",
            "example": "Re-accreditation 2026"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "closed"
            ],
            "example": "active"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "packId": "au-aged-care-strengthened",
          "profileId": "cat6",
          "cycleLabel": "Re-accreditation 2026",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "EngagementInput": {
        "type": "object",
        "required": [
          "accountId",
          "packId"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000003"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "packVersion": {
            "type": "string",
            "example": "0.1.0"
          },
          "profileId": {
            "type": "string",
            "example": "cat6"
          },
          "cycleLabel": {
            "type": "string",
            "example": "Re-accreditation 2026"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "closed"
            ],
            "example": "active"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "packId": "au-aged-care-strengthened",
          "profileId": "cat6",
          "cycleLabel": "Re-accreditation 2026"
        }
      },
      "Assessment": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "engagementId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000010"
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "self",
              "external",
              "mock"
            ],
            "example": "external"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "in_progress",
              "submitted",
              "under_review",
              "decided",
              "closed"
            ],
            "example": "in_progress"
          },
          "title": {
            "type": "string",
            "example": "Site audit: Wattle Grove Residential"
          },
          "scheduledFrom": {
            "type": "string",
            "format": "date",
            "example": "2026-10-22"
          },
          "scheduledTo": {
            "type": "string",
            "format": "date"
          },
          "team": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "u-helen"
            },
            "description": "Assessor ids; assignment runs COI checks"
          },
          "readiness": {
            "type": "number",
            "example": 0.78,
            "readOnly": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "engagementId": "00000000-0000-0000-0000-000000000010",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "kind": "external",
          "title": "Site audit: Wattle Grove Residential",
          "scheduledFrom": "2026-10-22",
          "team": [
            "u-helen"
          ],
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "AssessmentInput": {
        "type": "object",
        "required": [
          "accountId",
          "kind",
          "title"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "engagementId": {
            "type": "string",
            "format": "uuid",
            "example": "00000000-0000-0000-0000-000000000010"
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "self",
              "external",
              "mock"
            ],
            "example": "external"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "in_progress",
              "submitted",
              "under_review",
              "decided",
              "closed"
            ],
            "example": "in_progress"
          },
          "title": {
            "type": "string",
            "example": "Site audit: Wattle Grove Residential"
          },
          "scheduledFrom": {
            "type": "string",
            "format": "date",
            "example": "2026-10-22"
          },
          "scheduledTo": {
            "type": "string",
            "format": "date"
          },
          "team": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "u-helen"
            },
            "description": "Assessor ids; assignment runs COI checks"
          }
        },
        "example": {
          "engagementId": "00000000-0000-0000-0000-000000000010",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "kind": "external",
          "title": "Site audit: Wattle Grove Residential",
          "scheduledFrom": "2026-10-22",
          "team": [
            "u-helen"
          ]
        }
      },
      "Finding": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "elementId": {
            "type": "string",
            "example": "1.1"
          },
          "severity": {
            "type": "string",
            "enum": [
              "observation",
              "minor",
              "major",
              "critical"
            ]
          },
          "statement": {
            "type": "string"
          },
          "raisedAt": {
            "type": "string",
            "format": "date-time"
          },
          "closedAt": {
            "type": "string",
            "format": "date-time"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "assessmentId": "demo-aged-1",
          "elementId": "1.1",
          "severity": "minor",
          "statement": "Two of three sampled care plans had no documented personal goals",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "FindingInput": {
        "type": "object",
        "required": [],
        "properties": {
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "elementId": {
            "type": "string",
            "example": "1.1"
          },
          "severity": {
            "type": "string",
            "enum": [
              "observation",
              "minor",
              "major",
              "critical"
            ]
          },
          "statement": {
            "type": "string"
          },
          "raisedAt": {
            "type": "string",
            "format": "date-time"
          },
          "closedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "assessmentId": "demo-aged-1",
          "elementId": "1.1",
          "severity": "minor",
          "statement": "Two of three sampled care plans had no documented personal goals"
        }
      },
      "Action": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "findingId": {
            "type": "string",
            "format": "uuid"
          },
          "elementId": {
            "type": "string",
            "example": "2.8"
          },
          "title": {
            "type": "string",
            "example": "Publish care-minutes roster"
          },
          "ownerEmail": {
            "type": "string"
          },
          "dueOn": {
            "type": "string",
            "format": "date",
            "example": "2026-11-30"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "in_progress",
              "verified",
              "closed",
              "overdue"
            ],
            "example": "open"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "assessmentId": "demo-aged-self",
          "elementId": "2.8",
          "title": "Publish care-minutes roster and RN coverage plan for Q4",
          "dueOn": "2026-11-30",
          "status": "open",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "ActionInput": {
        "type": "object",
        "required": [
          "title"
        ],
        "properties": {
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "findingId": {
            "type": "string",
            "format": "uuid"
          },
          "elementId": {
            "type": "string",
            "example": "2.8"
          },
          "title": {
            "type": "string",
            "example": "Publish care-minutes roster"
          },
          "ownerEmail": {
            "type": "string"
          },
          "dueOn": {
            "type": "string",
            "format": "date",
            "example": "2026-11-30"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "in_progress",
              "verified",
              "closed",
              "overdue"
            ],
            "example": "open"
          }
        },
        "example": {
          "assessmentId": "demo-aged-self",
          "elementId": "2.8",
          "title": "Publish care-minutes roster and RN coverage plan for Q4",
          "dueOn": "2026-11-30",
          "status": "open"
        }
      },
      "Decision": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited"
            ]
          },
          "conditions": {
            "type": "string"
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2026-0212"
          },
          "validFrom": {
            "type": "string",
            "format": "date"
          },
          "validTo": {
            "type": "string",
            "format": "date"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "assessmentId": "demo-aged-1",
          "outcome": "accredited",
          "certificateNumber": "NAP-2026-0212",
          "validFrom": "2026-11-14",
          "validTo": "2029-11-13",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "DecisionInput": {
        "type": "object",
        "required": [
          "assessmentId",
          "outcome"
        ],
        "properties": {
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited"
            ]
          },
          "conditions": {
            "type": "string"
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2026-0212"
          },
          "validFrom": {
            "type": "string",
            "format": "date"
          },
          "validTo": {
            "type": "string",
            "format": "date"
          }
        },
        "example": {
          "assessmentId": "demo-aged-1",
          "outcome": "accredited",
          "certificateNumber": "NAP-2026-0212",
          "validFrom": "2026-11-14",
          "validTo": "2029-11-13"
        }
      },
      "Historicaldecision": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "programme": {
            "type": "string",
            "example": "Aged Care Quality Standards (2019 edition)"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited",
              "withdrawn"
            ]
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2023-0187"
          },
          "decidedOn": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "validFrom": {
            "type": "string",
            "format": "date"
          },
          "validTo": {
            "type": "string",
            "format": "date"
          },
          "assessors": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "ASR-12"
            },
            "description": "Assessor external ids or names on the team"
          },
          "findingsSummary": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "elementId": "2.5",
                "severity": "minor",
                "statement": "Incident register incomplete"
              }
            }
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "programme": "Aged Care Quality Standards (2019 edition)",
          "outcome": "accredited",
          "certificateNumber": "NAP-2023-0187",
          "decidedOn": "2023-11-14",
          "validFrom": "2023-11-14",
          "validTo": "2026-11-13",
          "assessors": [
            "ASR-12"
          ],
          "source": "legacy-access-db",
          "externalId": "DEC-2023-0187",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "HistoricaldecisionInput": {
        "type": "object",
        "required": [
          "accountId",
          "programme",
          "outcome",
          "decidedOn"
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "programme": {
            "type": "string",
            "example": "Aged Care Quality Standards (2019 edition)"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited",
              "withdrawn"
            ]
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2023-0187"
          },
          "decidedOn": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "validFrom": {
            "type": "string",
            "format": "date"
          },
          "validTo": {
            "type": "string",
            "format": "date"
          },
          "assessors": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "ASR-12"
            },
            "description": "Assessor external ids or names on the team"
          },
          "findingsSummary": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true,
              "example": {
                "elementId": "2.5",
                "severity": "minor",
                "statement": "Incident register incomplete"
              }
            }
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "programme": "Aged Care Quality Standards (2019 edition)",
          "outcome": "accredited",
          "certificateNumber": "NAP-2023-0187",
          "decidedOn": "2023-11-14",
          "validFrom": "2023-11-14",
          "validTo": "2026-11-13",
          "assessors": [
            "ASR-12"
          ],
          "source": "legacy-access-db",
          "externalId": "DEC-2023-0187"
        }
      },
      "Site": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "example": "Wattle Grove Residential"
          },
          "kind": {
            "type": "string",
            "enum": [
              "practice",
              "clinic",
              "hospital",
              "imaging",
              "dental",
              "residential",
              "home-care",
              "pharmacy",
              "office",
              "other"
            ],
            "example": "residential"
          },
          "address": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "line1": "14 Wattle St",
              "suburb": "Carseldine",
              "state": "QLD",
              "postcode": "4034"
            }
          },
          "phone": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "serviceTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "residential-aged-care"
            }
          },
          "isPrimary": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "name": "Wattle Grove Residential",
          "kind": "residential",
          "address": {
            "line1": "14 Wattle St",
            "suburb": "Carseldine",
            "state": "QLD",
            "postcode": "4034"
          },
          "serviceTypes": [
            "residential-aged-care"
          ],
          "isPrimary": true,
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "SiteInput": {
        "type": "object",
        "required": [
          "accountId",
          "name"
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "example": "Wattle Grove Residential"
          },
          "kind": {
            "type": "string",
            "enum": [
              "practice",
              "clinic",
              "hospital",
              "imaging",
              "dental",
              "residential",
              "home-care",
              "pharmacy",
              "office",
              "other"
            ],
            "example": "residential"
          },
          "address": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "line1": "14 Wattle St",
              "suburb": "Carseldine",
              "state": "QLD",
              "postcode": "4034"
            }
          },
          "phone": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "serviceTypes": {
            "type": "array",
            "items": {
              "type": "string",
              "example": "residential-aged-care"
            }
          },
          "isPrimary": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "name": "Wattle Grove Residential",
          "kind": "residential",
          "address": {
            "line1": "14 Wattle St",
            "suburb": "Carseldine",
            "state": "QLD",
            "postcode": "4034"
          },
          "serviceTypes": [
            "residential-aged-care"
          ],
          "isPrimary": true
        }
      },
      "Invitation": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "email": {
            "type": "string",
            "example": "new.manager@wattlegrove.example"
          },
          "role": {
            "type": "string",
            "enum": [
              "agency_admin",
              "assessor",
              "account_admin",
              "account_contributor",
              "viewer"
            ],
            "example": "account_contributor"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "expired",
              "revoked"
            ],
            "readOnly": true
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "acceptUrl": {
            "type": "string",
            "description": "Returned once on creation",
            "readOnly": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "email": "new.manager@wattlegrove.example",
          "role": "account_contributor",
          "message": "Please help with the clinical care standard.",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "InvitationInput": {
        "type": "object",
        "required": [
          "email",
          "role"
        ],
        "properties": {
          "email": {
            "type": "string",
            "example": "new.manager@wattlegrove.example"
          },
          "role": {
            "type": "string",
            "enum": [
              "agency_admin",
              "assessor",
              "account_admin",
              "account_contributor",
              "viewer"
            ],
            "example": "account_contributor"
          },
          "message": {
            "type": "string"
          }
        },
        "example": {
          "email": "new.manager@wattlegrove.example",
          "role": "account_contributor",
          "message": "Please help with the clinical care standard."
        }
      },
      "Changenotification": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "address",
              "name",
              "ownership",
              "site_added",
              "site_closed",
              "service_types",
              "contact"
            ]
          },
          "entityType": {
            "type": "string"
          },
          "entityId": {
            "type": "string"
          },
          "before": {
            "type": "object",
            "additionalProperties": true
          },
          "after": {
            "type": "object",
            "additionalProperties": true
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "acknowledged",
              "action_required"
            ],
            "example": "pending"
          },
          "agencyNote": {
            "type": "string"
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "acknowledgedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "kind": "address",
          "entityType": "site",
          "after": {
            "line1": "16 Wattle St",
            "suburb": "Carseldine",
            "state": "QLD",
            "postcode": "4034"
          },
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "ChangenotificationInput": {
        "type": "object",
        "required": [
          "accountId",
          "kind"
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "address",
              "name",
              "ownership",
              "site_added",
              "site_closed",
              "service_types",
              "contact"
            ]
          },
          "entityType": {
            "type": "string"
          },
          "entityId": {
            "type": "string"
          },
          "before": {
            "type": "object",
            "additionalProperties": true
          },
          "after": {
            "type": "object",
            "additionalProperties": true
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "acknowledged",
              "action_required"
            ],
            "example": "pending"
          },
          "agencyNote": {
            "type": "string"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "kind": "address",
          "entityType": "site",
          "after": {
            "line1": "16 Wattle St",
            "suburb": "Carseldine",
            "state": "QLD",
            "postcode": "4034"
          }
        }
      },
      "Member": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "userId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "inherited": {
            "type": "boolean",
            "description": "True when the role comes from a parent account (group head office)"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "userId": "u-priya",
          "name": "Priya Nair",
          "email": "priya@wattlegrove.example",
          "role": "account_admin",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "MemberInput": {
        "type": "object",
        "required": [],
        "properties": {
          "userId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string"
          },
          "inherited": {
            "type": "boolean",
            "description": "True when the role comes from a parent account (group head office)"
          }
        },
        "example": {
          "userId": "u-priya",
          "name": "Priya Nair",
          "email": "priya@wattlegrove.example",
          "role": "account_admin"
        }
      },
      "Evidence": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "title": {
            "type": "string",
            "example": "Infection prevention and control policy v4"
          },
          "mimeType": {
            "type": "string",
            "example": "application/pdf"
          },
          "sizeBytes": {
            "type": "number"
          },
          "sha256": {
            "type": "string"
          },
          "version": {
            "type": "number"
          },
          "supersedes": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "stored",
              "quarantined",
              "deleted"
            ]
          },
          "scanStatus": {
            "type": "string",
            "enum": [
              "pending",
              "clean",
              "infected",
              "skipped"
            ]
          },
          "approvedOn": {
            "type": "string",
            "format": "date"
          },
          "reviewDueOn": {
            "type": "string",
            "format": "date",
            "description": "Expiring evidence raises an action 30 days before"
          },
          "retentionUntil": {
            "type": "string",
            "format": "date-time"
          },
          "legalHold": {
            "type": "boolean"
          },
          "kind": {
            "type": "string",
            "enum": [
              "upload",
              "generated"
            ],
            "description": "generated = report or certificate PDF produced by Vidima IQ"
          },
          "documentType": {
            "type": "string",
            "enum": [
              "certificate",
              "report"
            ]
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "siteId": {
            "type": "string",
            "format": "uuid"
          },
          "storagePath": {
            "type": "string",
            "readOnly": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "title": "Infection prevention and control policy v4",
          "mimeType": "application/pdf",
          "sizeBytes": 482113,
          "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
          "version": 4,
          "status": "stored",
          "scanStatus": "clean",
          "approvedOn": "2026-07-01",
          "reviewDueOn": "2027-07-01",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "EvidenceInput": {
        "type": "object",
        "required": [],
        "properties": {
          "title": {
            "type": "string",
            "example": "Infection prevention and control policy v4"
          },
          "mimeType": {
            "type": "string",
            "example": "application/pdf"
          },
          "sizeBytes": {
            "type": "number"
          },
          "sha256": {
            "type": "string"
          },
          "version": {
            "type": "number"
          },
          "supersedes": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "stored",
              "quarantined",
              "deleted"
            ]
          },
          "scanStatus": {
            "type": "string",
            "enum": [
              "pending",
              "clean",
              "infected",
              "skipped"
            ]
          },
          "approvedOn": {
            "type": "string",
            "format": "date"
          },
          "reviewDueOn": {
            "type": "string",
            "format": "date",
            "description": "Expiring evidence raises an action 30 days before"
          },
          "retentionUntil": {
            "type": "string",
            "format": "date-time"
          },
          "legalHold": {
            "type": "boolean"
          },
          "kind": {
            "type": "string",
            "enum": [
              "upload",
              "generated"
            ],
            "description": "generated = report or certificate PDF produced by Vidima IQ"
          },
          "documentType": {
            "type": "string",
            "enum": [
              "certificate",
              "report"
            ]
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "siteId": {
            "type": "string",
            "format": "uuid"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "example": {
          "title": "Infection prevention and control policy v4",
          "mimeType": "application/pdf",
          "sizeBytes": 482113,
          "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
          "version": 4,
          "status": "stored",
          "scanStatus": "clean",
          "approvedOn": "2026-07-01",
          "reviewDueOn": "2027-07-01",
          "accountId": "00000000-0000-0000-0000-000000000003"
        }
      },
      "Evidencelink": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "evidenceId": {
            "type": "string",
            "format": "uuid"
          },
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "elementId": {
            "type": "string",
            "example": "4.2"
          },
          "via": {
            "type": "string",
            "enum": [
              "manual",
              "crosswalk",
              "ai-proposed",
              "ai-confirmed"
            ]
          },
          "confidence": {
            "type": "number"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "evidenceId": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "packId": "au-aged-care-strengthened",
          "elementId": "4.2",
          "via": "manual",
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "EvidencelinkInput": {
        "type": "object",
        "required": [],
        "properties": {
          "evidenceId": {
            "type": "string",
            "format": "uuid"
          },
          "assessmentId": {
            "type": "string",
            "format": "uuid"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "elementId": {
            "type": "string",
            "example": "4.2"
          },
          "via": {
            "type": "string",
            "enum": [
              "manual",
              "crosswalk",
              "ai-proposed",
              "ai-confirmed"
            ]
          },
          "confidence": {
            "type": "number"
          }
        },
        "example": {
          "evidenceId": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "packId": "au-aged-care-strengthened",
          "elementId": "4.2",
          "via": "manual"
        }
      },
      "Certificate": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Vidima IQ id",
            "example": "00000000-0000-0000-0000-000000000003",
            "readOnly": true
          },
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "programme": {
            "type": "string",
            "description": "Standard and edition as named on the certificate; free text so old editions survive migration",
            "example": "Aged Care Quality Standards (2019 edition)"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "packVersion": {
            "type": "string"
          },
          "edition": {
            "type": "string"
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2023-0187"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited",
              "withdrawn"
            ]
          },
          "conditions": {
            "type": "string"
          },
          "decidedOn": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "cycleStart": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "cycleEnd": {
            "type": "string",
            "format": "date",
            "example": "2026-11-13"
          },
          "cycleLabel": {
            "type": "string",
            "example": "2023-2026 cycle"
          },
          "validFrom": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "validTo": {
            "type": "string",
            "format": "date",
            "description": "Expiry",
            "example": "2026-11-13"
          },
          "status": {
            "type": "string",
            "enum": [
              "current",
              "expiring",
              "expired",
              "superseded",
              "withdrawn",
              "suspended"
            ],
            "description": "Derived from dates unless withdrawn, suspended or superseded"
          },
          "supersededBy": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "supersedes": {
            "type": "string",
            "format": "uuid",
            "description": "Certificate this one replaces (e.g. the previous edition of the standard); it is marked superseded"
          },
          "siteIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Empty = all sites"
          },
          "decisionId": {
            "type": "string",
            "format": "uuid"
          },
          "historicalDecisionId": {
            "type": "string",
            "format": "uuid"
          },
          "documentId": {
            "type": "string",
            "format": "uuid",
            "description": "Evidence id of the PDF (generated or uploaded scan)"
          },
          "legacy": {
            "type": "object",
            "additionalProperties": true,
            "description": "Provenance from the previous platform: system, recordId, notes",
            "example": {
              "system": "AccreditationPro",
              "recordId": "CERT-0187"
            }
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          },
          "tenantId": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "example": {
          "id": "3f2a0b6e-7c1d-4e8a-9f00-1234567890ab",
          "tenantId": "00000000-0000-0000-0000-000000000002",
          "accountId": "00000000-0000-0000-0000-000000000003",
          "programme": "Aged Care Quality Standards (2019 edition)",
          "certificateNumber": "NAP-2023-0187",
          "outcome": "accredited",
          "decidedOn": "2023-11-14",
          "cycleStart": "2023-11-14",
          "cycleEnd": "2026-11-13",
          "cycleLabel": "2023-2026 cycle",
          "validFrom": "2023-11-14",
          "validTo": "2026-11-13",
          "source": "legacy",
          "externalId": "CERT-0187",
          "legacy": {
            "system": "AccreditationPro",
            "recordId": "CERT-0187"
          },
          "createdAt": "2026-09-13T02:00:00Z",
          "updatedAt": "2026-09-13T02:00:00Z"
        }
      },
      "CertificateInput": {
        "type": "object",
        "required": [
          "accountId",
          "programme",
          "certificateNumber",
          "outcome",
          "validFrom",
          "validTo"
        ],
        "properties": {
          "custom": {
            "type": "object",
            "additionalProperties": true,
            "description": "This tenant's custom fields as { key: value }. Definitions (key, type, options, required) come from GET /custom-fields; unknown keys are rejected. On PATCH, keys you send are merged and null clears a value.",
            "example": {
              "region": "South East Queensland",
              "beds": 120,
              "fundedPlaces": true
            }
          },
          "accountId": {
            "type": "string",
            "format": "uuid"
          },
          "programme": {
            "type": "string",
            "description": "Standard and edition as named on the certificate; free text so old editions survive migration",
            "example": "Aged Care Quality Standards (2019 edition)"
          },
          "packId": {
            "type": "string",
            "example": "au-aged-care-strengthened"
          },
          "packVersion": {
            "type": "string"
          },
          "edition": {
            "type": "string"
          },
          "certificateNumber": {
            "type": "string",
            "example": "NAP-2023-0187"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "accredited",
              "conditional",
              "not_accredited",
              "withdrawn"
            ]
          },
          "conditions": {
            "type": "string"
          },
          "decidedOn": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "cycleStart": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "cycleEnd": {
            "type": "string",
            "format": "date",
            "example": "2026-11-13"
          },
          "cycleLabel": {
            "type": "string",
            "example": "2023-2026 cycle"
          },
          "validFrom": {
            "type": "string",
            "format": "date",
            "example": "2023-11-14"
          },
          "validTo": {
            "type": "string",
            "format": "date",
            "description": "Expiry",
            "example": "2026-11-13"
          },
          "status": {
            "type": "string",
            "enum": [
              "current",
              "expiring",
              "expired",
              "superseded",
              "withdrawn",
              "suspended"
            ],
            "description": "Derived from dates unless withdrawn, suspended or superseded"
          },
          "supersedes": {
            "type": "string",
            "format": "uuid",
            "description": "Certificate this one replaces (e.g. the previous edition of the standard); it is marked superseded"
          },
          "siteIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Empty = all sites"
          },
          "decisionId": {
            "type": "string",
            "format": "uuid"
          },
          "historicalDecisionId": {
            "type": "string",
            "format": "uuid"
          },
          "documentId": {
            "type": "string",
            "format": "uuid",
            "description": "Evidence id of the PDF (generated or uploaded scan)"
          },
          "legacy": {
            "type": "object",
            "additionalProperties": true,
            "description": "Provenance from the previous platform: system, recordId, notes",
            "example": {
              "system": "AccreditationPro",
              "recordId": "CERT-0187"
            }
          },
          "source": {
            "type": "string",
            "description": "External system name used for idempotent upserts (e.g. dynamics365, hubspot, legacy-access-db)",
            "example": "dynamics365"
          },
          "externalId": {
            "type": "string",
            "description": "Id of this record in the external system",
            "example": "ACC-00042"
          }
        },
        "example": {
          "accountId": "00000000-0000-0000-0000-000000000003",
          "programme": "Aged Care Quality Standards (2019 edition)",
          "certificateNumber": "NAP-2023-0187",
          "outcome": "accredited",
          "decidedOn": "2023-11-14",
          "cycleStart": "2023-11-14",
          "cycleEnd": "2026-11-13",
          "cycleLabel": "2023-2026 cycle",
          "validFrom": "2023-11-14",
          "validTo": "2026-11-13",
          "source": "legacy",
          "externalId": "CERT-0187",
          "legacy": {
            "system": "AccreditationPro",
            "recordId": "CERT-0187"
          }
        }
      },
      "WebhookSubscription": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "description": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "secretPrefix": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "id": "wh-demo-1",
          "url": "https://example.crm.invalid/vidimaiq/webhook",
          "events": [
            "assessment.submitted",
            "decision.recorded"
          ],
          "description": "Dynamics 365 via Power Automate",
          "active": true,
          "secretPrefix": "whsec_demo",
          "createdAt": "2026-09-13T02:00:00Z"
        }
      },
      "WebhookEnvelope": {
        "type": "object",
        "description": "What Vidima IQ POSTs to your URL. Verify the Vidima-Signature header: HMAC-SHA256 of `${t}.${rawBody}` with your secret.",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "entity": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "data": {
            "type": "object"
          },
          "apiVersion": {
            "type": "string"
          }
        },
        "example": {
          "id": "8e1c…",
          "type": "assessment.submitted",
          "occurredAt": "2026-10-01T03:12:00Z",
          "entity": {
            "type": "assessment",
            "id": "demo-aged-self"
          },
          "data": {
            "credentialId": "5b1d…",
            "assessorUserId": "u-lee",
            "assessorName": "Lee Tan",
            "kind": "surveyor-training",
            "expiresAt": "2028-09-30",
            "needsVerification": true
          },
          "apiVersion": "2026-09-01"
        }
      },
      "Delivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "subscriptionId": {
            "type": "string"
          },
          "eventId": {
            "type": "string"
          },
          "attempt": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "delivered",
              "failed",
              "dead"
            ]
          },
          "nextAttemptAt": {
            "type": "string"
          },
          "lastStatusCode": {
            "type": [
              "integer",
              "null"
            ]
          },
          "lastError": {
            "type": "string"
          },
          "deliveredAt": {
            "type": "string"
          }
        }
      },
      "ImportRequest": {
        "type": "object",
        "required": [
          "entityType",
          "source"
        ],
        "properties": {
          "entityType": {
            "type": "string",
            "enum": [
              "accounts",
              "contacts",
              "assessors",
              "engagements",
              "decisions",
              "certificates"
            ]
          },
          "source": {
            "type": "string",
            "example": "legacy-access-db"
          },
          "dryRun": {
            "type": "boolean",
            "default": true,
            "description": "Validate only; nothing is written. Run again with false to commit."
          },
          "mapping": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Column name in your file -> Vidima IQ field",
            "example": {
              "Facility Name": "name",
              "ABN": "abn",
              "Legacy ID": "externalId"
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "csv": {
            "type": "string",
            "description": "Alternatively, raw CSV text with a header row"
          }
        },
        "example": {
          "entityType": "decisions",
          "source": "legacy-access-db",
          "dryRun": false,
          "mapping": {
            "Facility ID": "accountExternalId",
            "Program": "programme",
            "Result": "outcome",
            "Cert No": "certificateNumber",
            "Decision Date": "decidedOn",
            "Expiry": "validTo",
            "Surveyors": "assessors",
            "Decision ID": "externalId"
          },
          "rows": [
            {
              "Facility ID": "ACC-00042",
              "Program": "Aged Care Quality Standards (2019 edition)",
              "Result": "accredited",
              "Cert No": "NAP-2023-0187",
              "Decision Date": "14/11/2023",
              "Expiry": "13/11/2026",
              "Surveyors": "ASR-12;ASR-19",
              "Decision ID": "DEC-2023-0187"
            }
          ]
        }
      },
      "ImportJob": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "entityType": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "validating",
              "ready",
              "running",
              "completed",
              "failed"
            ]
          },
          "dryRun": {
            "type": "boolean"
          },
          "totals": {
            "type": "object",
            "example": {
              "rows": 120,
              "valid": 118,
              "invalid": 2,
              "created": 0,
              "updated": 0,
              "skipped": 0
            }
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "rowNo": {
                  "type": "integer"
                },
                "status": {
                  "type": "string"
                },
                "errors": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "entityId": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "UploadRequest": {
        "type": "object",
        "required": [
          "fileName",
          "mime",
          "sizeBytes"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "fileName": {
            "type": "string"
          },
          "mime": {
            "type": "string"
          },
          "sizeBytes": {
            "type": "integer"
          },
          "sha256": {
            "type": "string",
            "description": "Optional; if a stored file with the same hash exists it is returned instead (deduplicated: true)"
          },
          "elementId": {
            "type": "string"
          },
          "packId": {
            "type": "string"
          },
          "assessmentId": {
            "type": "string"
          },
          "supersedes": {
            "type": "string",
            "description": "Evidence id this file replaces (new version)"
          },
          "approvedOn": {
            "type": "string",
            "format": "date"
          },
          "reviewDueOn": {
            "type": "string",
            "format": "date"
          },
          "accountId": {
            "type": "string"
          },
          "siteId": {
            "type": "string"
          }
        },
        "example": {
          "title": "Infection prevention and control policy v4",
          "fileName": "ipc-policy-v4.pdf",
          "mime": "application/pdf",
          "sizeBytes": 482113,
          "sha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
          "packId": "au-aged-care-strengthened",
          "elementId": "4.2",
          "approvedOn": "2026-07-01",
          "reviewDueOn": "2027-07-01"
        }
      },
      "IdentityProvider": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "tenantId": {
            "type": "string"
          },
          "protocol": {
            "type": "string",
            "enum": [
              "oidc",
              "saml"
            ]
          },
          "preset": {
            "type": "string",
            "enum": [
              "entra-id",
              "auth0",
              "okta",
              "google",
              "generic-oidc",
              "generic-saml"
            ]
          },
          "name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "enforce": {
            "type": "boolean",
            "description": "Disable password sign-in for these domains"
          },
          "config": {
            "type": "object",
            "description": "Preset-specific: tenantId/clientId/scopes/groupsClaim (OIDC) or entryPoint/idpIssuer/idpCert/groupsAttribute (SAML)"
          },
          "hasClientSecret": {
            "type": "boolean",
            "readOnly": true
          },
          "domains": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "jitProvisioning": {
            "type": "boolean"
          },
          "defaultRole": {
            "type": "string"
          },
          "roleMapping": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "group": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                }
              }
            }
          }
        },
        "example": {
          "id": "idp-demo-entra",
          "protocol": "oidc",
          "preset": "entra-id",
          "name": "North Audit staff (Entra ID)",
          "enabled": true,
          "enforce": false,
          "config": {
            "tenantId": "11111111-2222-3333-4444-555555555555",
            "clientId": "a1b2c3d4",
            "scopes": "openid profile email",
            "groupsClaim": "groups"
          },
          "hasClientSecret": true,
          "domains": [
            "northaudit.example"
          ],
          "jitProvisioning": true,
          "defaultRole": "assessor",
          "roleMapping": [
            {
              "group": "Vidima-Agency-Admins",
              "role": "agency_admin"
            }
          ]
        }
      }
    }
  },
  "x-events": [
    {
      "type": "account.created",
      "description": "An account (practice, home, provider) was created or imported for the agency.",
      "example": {
        "accountId": "00000000-0000-0000-0000-000000000003",
        "name": "Wattle Grove Aged Care",
        "source": "dynamics365",
        "externalId": "ACC-00042"
      }
    },
    {
      "type": "account.change_submitted",
      "description": "An account changed its address, name, ownership, sites or services through self-service; the agency must acknowledge.",
      "example": {
        "accountId": "00000000-0000-0000-0000-000000000003",
        "changeRequestId": "7b1c…",
        "kind": "address",
        "after": {
          "address": {
            "line1": "16 Wattle St",
            "suburb": "Carseldine",
            "state": "QLD",
            "postcode": "4034"
          }
        }
      }
    },
    {
      "type": "evidence.stored",
      "description": "A file finished uploading and is available (subject to virus scan).",
      "example": {
        "evidenceId": "3f2a…",
        "title": "Infection control policy v4",
        "sizeBytes": 482113,
        "sha256": "9f86…"
      }
    },
    {
      "type": "certificate.issued",
      "description": "A certificate entered the register: issued by Vidima IQ, uploaded from a legacy platform, or imported.",
      "example": {
        "certificateId": "9c1e…",
        "accountId": "00000000-0000-0000-0000-000000000003",
        "certificateNumber": "NAP-2026-0212",
        "programme": "Strengthened Aged Care Quality Standards",
        "validFrom": "2026-11-14",
        "validTo": "2029-11-13",
        "source": "vidimaiq"
      }
    },
    {
      "type": "certificate.expiring",
      "description": "A current certificate is within 90 days of expiry (nightly sweep).",
      "example": {
        "certificateId": "9c1e…",
        "accountId": "…",
        "certificateNumber": "NAP-2023-0187",
        "validTo": "2026-11-13",
        "daysLeft": 61
      }
    },
    {
      "type": "credential.submitted",
      "description": "An assessor uploaded or entered a credential (training certificate, registration, screening check).",
      "example": {
        "credentialId": "5b1d…",
        "assessorUserId": "u-lee",
        "assessorName": "Lee Tan",
        "kind": "surveyor-training",
        "expiresAt": "2028-09-30",
        "needsVerification": true
      }
    },
    {
      "type": "credential.verified",
      "description": "An agency admin verified an assessor credential; it now counts towards eligibility.",
      "example": {
        "credentialId": "5b1d…",
        "assessorUserId": "u-lee",
        "kind": "surveyor-training",
        "expiresAt": "2028-09-30",
        "note": null
      }
    },
    {
      "type": "credential.rejected",
      "description": "An agency admin rejected an assessor credential, with the reason.",
      "example": {
        "credentialId": "5b1d…",
        "assessorUserId": "u-lee",
        "kind": "surveyor-training",
        "note": "Certificate is for the 2022 course; upload the 2026 refresher."
      }
    },
    {
      "type": "credential.expiring",
      "description": "A verified assessor credential is inside its type's reminder window (nightly sweep).",
      "example": {
        "credentialId": "5b1d…",
        "assessorUserId": "u-sam",
        "assessorName": "Dr Sam Whitfield",
        "kind": "surveyor-training",
        "expiresAt": "2026-10-22",
        "daysLeft": 21
      }
    },
    {
      "type": "document.generated",
      "description": "A report or certificate PDF was generated and stored; download it via /evidence/{id}/download.",
      "example": {
        "evidenceId": "3f2a…",
        "documentType": "certificate",
        "title": "Certificate NAP-2026-0A1B",
        "certificateNumber": "NAP-2026-0A1B",
        "accountId": "00000000-0000-0000-0000-000000000003"
      }
    },
    {
      "type": "report.delivered",
      "description": "A scheduled report ran: the file was saved and emailed to the named members on the schedule (attached up to 5 MB, otherwise a link back).",
      "example": {
        "runId": "9b1c…",
        "scheduleId": "4e2d…",
        "report": "expiries",
        "rows": 42,
        "sizeBytes": 18231,
        "delivery": "attached"
      }
    },
    {
      "type": "document.emailed",
      "description": "A generated document was emailed to a recipient.",
      "example": {
        "evidenceId": "3f2a…",
        "to": "priya@wattlegrove.example",
        "provider": "resend"
      }
    },
    {
      "type": "account.updated",
      "description": "Account details changed.",
      "example": {
        "accountId": "00000000-0000-0000-0000-000000000003",
        "changed": [
          "name",
          "sites"
        ]
      }
    },
    {
      "type": "contact.created",
      "description": "A contact was added to an account.",
      "example": {
        "contactId": "5c1e…",
        "accountId": "…",
        "email": "priya@wattlegrove.example"
      }
    },
    {
      "type": "engagement.created",
      "description": "An agency opened an accreditation cycle with an account.",
      "example": {
        "engagementId": "…",
        "accountId": "…",
        "packId": "au-aged-care-strengthened",
        "cycleLabel": "Re-accreditation 2026"
      }
    },
    {
      "type": "assessment.created",
      "description": "A self or external assessment was created.",
      "example": {
        "assessmentId": "…",
        "kind": "self",
        "accountId": "…"
      }
    },
    {
      "type": "assessment.submitted",
      "description": "An account submitted its self-assessment; or an assessor closed an external assessment.",
      "example": {
        "assessmentId": "demo-aged-self",
        "accountId": "…",
        "readiness": 0.78,
        "occurredAt": "2026-10-01T03:12:00Z"
      }
    },
    {
      "type": "assessment.team_assigned",
      "description": "Assessors were assigned (after conflict-of-interest checks).",
      "example": {
        "assessmentId": "…",
        "team": [
          {
            "userId": "u-helen",
            "role": "lead",
            "coiOverride": "rotation"
          }
        ]
      }
    },
    {
      "type": "finding.raised",
      "description": "An assessor raised a finding against an element.",
      "example": {
        "assessmentId": "…",
        "elementId": "1.1",
        "severity": "minor",
        "statement": "Two of three care plans had no documented goals"
      }
    },
    {
      "type": "action.created",
      "description": "A corrective action was created.",
      "example": {
        "actionId": "…",
        "title": "Publish care-minutes roster",
        "dueOn": "2026-11-30"
      }
    },
    {
      "type": "action.overdue",
      "description": "A corrective action passed its due date without closure (daily sweep).",
      "example": {
        "actionId": "…",
        "dueOn": "2026-11-30",
        "daysOverdue": 3
      }
    },
    {
      "type": "decision.recorded",
      "description": "The agency recorded an accreditation decision.",
      "example": {
        "decisionId": "…",
        "assessmentId": "…",
        "outcome": "accredited",
        "certificateNumber": "NAP-2026-0212",
        "validFrom": "2026-11-14",
        "validTo": "2029-11-13"
      }
    },
    {
      "type": "certificate.expiring",
      "description": "A certificate is within 90 days of expiry (daily sweep).",
      "example": {
        "accountId": "…",
        "certificateNumber": "NAP-2023-0187",
        "validTo": "2026-11-13"
      }
    },
    {
      "type": "import.completed",
      "description": "An import job finished.",
      "example": {
        "importId": "…",
        "entityType": "decisions",
        "totals": {
          "rows": 120,
          "created": 118,
          "updated": 2,
          "invalid": 0
        }
      }
    }
  ]
}