{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://alxprotocol.com/protocol/1/schemas/verification-context.schema.json",
  "title": "ALX Verification Context",
  "description": "Validation context passed to Graph verification operations. Declares the validation mode, graph root, intentional depth scope, execution budgets, and any external parent boundaries.",
  "$comment": "This schema validates context shape only. It is the context member of validateGraph(seed, source, context), does not itself authorize open-world validation, prove Graph validity, or define mixed-version compatibility semantics.",
  "type": "object",
  "properties": {
    "protocolVersion": {
      "type": "string",
      "const": "1",
      "description": "ALX Protocol version. Must be '1' for v1."
    },
    "validationMode": {
      "enum": ["closed-world", "open-world"],
      "description": "Validation mode: closed-world requires all parentHashes to resolve; open-world permits declared external boundaries."
    },
    "graphRoot": {
      "$ref": "./defs.schema.json#/$defs/hash",
      "description": "blockHash of the Block at the root of the graph being verified."
    },
    "maxDepth": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991,
      "description": "Optional inclusive verification-scope boundary measured in parent edges from graphRoot. This is a claim boundary, not an execution budget."
    },
    "resourceLimits": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "description": "Optional deterministic execution budgets. Exhaustion produces resource_limit_reached unless a known protocol violation takes precedence.",
      "properties": {
        "maxBlocks": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "Inclusive maximum number of distinct Blocks that may be examined."
        },
        "maxEdges": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991,
          "description": "Inclusive maximum number of parent relationships that may be examined."
        }
      }
    },
    "extensions": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128
      },
      "uniqueItems": true,
      "default": [],
      "description": "Extension identifiers active during this verification run."
    },
    "externalParents": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "hash": {
            "$ref": "./defs.schema.json#/$defs/hash",
            "description": "blockHash of the external parent being declared."
          },
          "reason": {
            "enum": [
              "external-boundary",
              "private-boundary",
              "unavailable-boundary",
              "unknown-boundary"
            ],
            "description": "Boundary classification: external-boundary (outside this system), private-boundary (access-restricted), unavailable-boundary (temporarily unavailable), unknown-boundary (classification unknown)."
          },
          "declaredBy": {
            "const": "verification-context",
            "description": "Source of this boundary declaration. Always 'verification-context' for context-declared boundaries."
          },
          "requiredForFullValidation": {
            "type": "boolean",
            "description": "True if resolving this parent would be required for a complete closed-world verification."
          }
        },
        "required": ["hash", "reason", "declaredBy", "requiredForFullValidation"],
        "additionalProperties": false
      },
      "uniqueItems": true,
      "description": "Parent hashes explicitly declared as external boundaries. Permits open-world verification without treating these as missing parents."
    }
  },
  "required": ["protocolVersion", "validationMode", "graphRoot", "externalParents"],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": { "validationMode": { "const": "closed-world" } },
        "required": ["validationMode"]
      },
      "then": {
        "properties": { "externalParents": { "type": "array", "maxItems": 0 } }
      }
    }
  ]
}
