{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "additionalProperties": false,
 "allOf": [
  {
   "if": {
    "properties": {
     "outcome": {
      "const": "REVISE"
     }
    }
   },
   "then": {
    "properties": {
     "findings": {
      "minItems": 1
     },
     "next_actor": {
      "const": "builder"
     }
    }
   }
  },
  {
   "if": {
    "properties": {
     "outcome": {
      "enum": [
       "READY_REVIEW",
       "PASS"
      ]
     }
    }
   },
   "then": {
    "properties": {
     "candidate_sha": {
      "pattern": "^[0-9a-f]{40}$",
      "type": "string"
     },
     "evidence_refs": {
      "minItems": 1
     }
    }
   }
  },
  {
   "if": {
    "properties": {
     "outcome": {
      "enum": [
       "BLOCKED",
       "NEEDS_OWNER"
      ]
     }
    }
   },
   "then": {
    "properties": {
     "blocker": {
      "additionalProperties": false,
      "properties": {
       "category": {
        "enum": [
         "ACCESS",
         "AUTH",
         "RUNTIME",
         "NETWORK",
         "INPUT",
         "OWNER_DECISION",
         "BUDGET",
         "POLICY",
         "INTEGRITY"
        ]
       },
       "observed": {
        "minLength": 1,
        "type": "string"
       }
      },
      "required": [
       "category",
       "observed"
      ],
      "type": "object"
     },
     "resume_condition": {
      "minLength": 1,
      "type": "string"
     }
    }
   }
  }
 ],
 "properties": {
  "blocker": {
   "oneOf": [
    {
     "type": "null"
    },
    {
     "additionalProperties": false,
     "properties": {
      "category": {
       "enum": [
        "ACCESS",
        "AUTH",
        "RUNTIME",
        "NETWORK",
        "INPUT",
        "OWNER_DECISION",
        "BUDGET",
        "POLICY",
        "INTEGRITY"
       ]
      },
      "observed": {
       "minLength": 1,
       "type": "string"
      }
     },
     "required": [
      "category",
      "observed"
     ],
     "type": "object"
    }
   ]
  },
  "candidate_sha": {
   "oneOf": [
    {
     "type": "null"
    },
    {
     "pattern": "^[0-9a-f]{40}$",
     "type": "string"
    }
   ]
  },
  "dispatch_id": {
   "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
   "type": "string"
  },
  "evidence_refs": {
   "items": {
    "additionalProperties": false,
    "properties": {
     "path": {
      "maxLength": 240,
      "minLength": 1,
      "type": "string"
     },
     "sha256": {
      "pattern": "^[0-9a-f]{64}$",
      "type": "string"
     }
    },
    "required": [
     "path",
     "sha256"
    ],
    "type": "object"
   },
   "maxItems": 32,
   "type": "array"
  },
  "findings": {
   "items": {
    "additionalProperties": false,
    "properties": {
     "expected_fix": {
      "minLength": 1,
      "type": "string"
     },
     "id": {
      "maxLength": 64,
      "minLength": 1,
      "type": "string"
     },
     "location": {
      "minLength": 1,
      "type": "string"
     },
     "problem": {
      "minLength": 1,
      "type": "string"
     },
     "recheck": {
      "minLength": 1,
      "type": "string"
     },
     "reproduce": {
      "minLength": 1,
      "type": "string"
     },
     "severity": {
      "enum": [
       "P0",
       "P1",
       "P2",
       "P3"
      ]
     }
    },
    "required": [
     "id",
     "severity",
     "location",
     "problem",
     "reproduce",
     "expected_fix",
     "recheck"
    ],
    "type": "object"
   },
   "maxItems": 64,
   "type": "array"
  },
  "message_id": {
   "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
   "type": "string"
  },
  "module_id": {
   "pattern": "^[A-Za-z0-9._-]{1,128}$",
   "type": "string"
  },
  "next_actor": {
   "enum": [
    "builder",
    "auditor",
    "owner",
    "none"
   ]
  },
  "outcome": {
   "enum": [
    "READY_REVIEW",
    "PASS",
    "REVISE",
    "BLOCKED",
    "NEEDS_OWNER"
   ]
  },
  "project_id": {
   "pattern": "^[A-Za-z0-9._-]{1,128}$",
   "type": "string"
  },
  "resume_condition": {
   "oneOf": [
    {
     "type": "null"
    },
    {
     "minLength": 1,
     "type": "string"
    }
   ]
  },
  "role": {
   "enum": [
    "builder",
    "auditor"
   ]
  },
  "run_id": {
   "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
   "type": "string"
  },
  "summary": {
   "minLength": 1,
   "type": "string"
  }
 },
 "required": [
  "project_id",
  "run_id",
  "message_id",
  "dispatch_id",
  "role",
  "module_id",
  "outcome",
  "candidate_sha",
  "summary",
  "evidence_refs",
  "findings",
  "blocker",
  "next_actor",
  "resume_condition"
 ],
 "type": "object"
}