{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qiheng.local/schemas/gate-cache.schema.json",
  "title": "QIHENG content-addressed gate cache",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "key",
    "inputHash",
    "planId",
    "profileHash",
    "candidateHash",
    "gateId",
    "cachedAt",
    "result"
  ],
  "properties": {
    "schema": { "const": "qiheng.gate-cache.v1" },
    "key": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "inputHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "planId": { "type": "string", "pattern": "^hplan-[a-f0-9]{16}$" },
    "profileHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "candidateHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "gateId": { "type": "string", "minLength": 1 },
    "cachedAt": { "type": "string", "format": "date-time" },
    "result": {
      "type": "object",
      "required": ["gateId", "status", "summary", "evidence", "handoffs"],
      "properties": {
        "gateId": { "type": "string", "minLength": 1 },
        "status": {
          "enum": ["PASS", "PASS_WITH_FOLLOW_UP", "SKIPPED"]
        },
        "summary": { "type": "string" },
        "evidence": { "type": "array" },
        "handoffs": { "type": "array" }
      }
    }
  }
}
