{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.firstmilelabs.com/schemas/webhooks/ai_review.completed.v1.json",
  "title": "FirstMileLabs Outbound Webhook — ai_review.completed (v1)",
  "description": "Emitted when the autonomous AI case review (AI screening) finishes for a case — fired both for analyst-triggered streaming reviews and for background reviews kicked off automatically after form submission or customer review confirmation.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "event",
    "eventId",
    "eventVersion",
    "timestamp",
    "orgId",
    "caseId",
    "reviewId",
    "recommendation",
    "confidence",
    "riskFactorCount",
    "riskFactors",
    "completedAt"
  ],
  "properties": {
    "event": { "type": "string", "const": "ai_review.completed" },
    "eventId": { "type": "string", "format": "uuid" },
    "eventVersion": { "type": "integer", "const": 1 },
    "timestamp": { "type": "string", "format": "date-time" },
    "orgId": { "type": "string" },
    "crmRecordId": { "type": ["string", "null"] },
    "caseId": { "type": "string" },
    "reviewId": { "type": "integer", "description": "Internal id of the case_ai_reviews row." },
    "companyName": { "type": ["string", "null"] },
    "triggeredBy": { "type": "string", "description": "Analyst email for streaming runs, or a \"system:form-submission:<email>\" / \"system:confirm-review:<email>\" tag for background runs." },
    "recommendation": { "type": "string", "enum": ["Approve", "Refer", "Decline"] },
    "confidence": { "type": "string", "enum": ["High", "Medium", "Low"] },
    "riskFactorCount": { "type": "integer", "minimum": 0 },
    "riskFactors": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["text", "severity"],
        "properties": {
          "text": { "type": "string" },
          "severity": { "type": "string", "enum": ["HIGH", "MEDIUM", "LOW"] }
        }
      }
    },
    "completedAt": { "type": "string", "format": "date-time" }
  }
}
