{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chris-page-gov.github.io/okf-explorer/profiles/context-assembly/v1/common.schema.json",
  "title": "Governed context assembly common definitions v1",
  "$defs": {
    "record": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "route": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        },
        "kind": {
          "enum": [
            "concept",
            "evidence",
            "scope"
          ]
        },
        "aliases": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string"
                  },
                  "case_sensitive": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "label",
                  "case_sensitive"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "text": {
          "type": "string"
        },
        "assertion_status": {
          "enum": [
            "official",
            "normalized",
            "inferred",
            "model-derived"
          ]
        },
        "authority": {
          "type": "object",
          "properties": {
            "class": {
              "type": "string"
            },
            "label": {
              "type": "string"
            },
            "source": {
              "type": "string"
            }
          },
          "required": [
            "class",
            "label",
            "source"
          ],
          "additionalProperties": false
        },
        "scope": {
          "type": "string"
        },
        "provenance": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "source_sha256": {
                "type": "string"
              },
              "locator": {
                "type": "string"
              },
              "captured_at": {
                "type": "string"
              },
              "source_date": {
                "type": "string"
              },
              "source_date_kind": {
                "type": "string"
              },
              "literal_sha256": {
                "type": "string"
              }
            },
            "required": [
              "url",
              "source_sha256",
              "locator",
              "captured_at"
            ],
            "additionalProperties": false
          }
        },
        "rights": {
          "type": "string"
        },
        "access": {
          "enum": [
            "public",
            "restricted"
          ]
        },
        "review_status": {
          "type": "string"
        },
        "conflicts_with": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "evidence_unit": {
          "$ref": "https://chris-page-gov.github.io/okf-explorer/profiles/context-assembly/v1/evidence-unit.schema.json"
        }
      },
      "required": [
        "id",
        "route",
        "label",
        "kind",
        "text",
        "assertion_status",
        "authority",
        "scope",
        "provenance",
        "rights",
        "access"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "required": [
              "evidence_unit"
            ]
          },
          "then": {
            "properties": {
              "kind": {
                "const": "evidence"
              }
            }
          }
        }
      ]
    },
    "assertion": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "predicate": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "assertion_status": {
          "enum": [
            "official",
            "normalized",
            "inferred",
            "model-derived"
          ]
        },
        "authority": {
          "type": "object",
          "properties": {
            "class": {
              "type": "string"
            },
            "label": {
              "type": "string"
            },
            "source": {
              "type": "string"
            }
          },
          "required": [
            "class",
            "label",
            "source"
          ],
          "additionalProperties": false
        },
        "scope": {
          "type": "string"
        },
        "provenance": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "source_sha256": {
                "type": "string"
              },
              "locator": {
                "type": "string"
              },
              "captured_at": {
                "type": "string"
              },
              "source_date": {
                "type": "string"
              },
              "source_date_kind": {
                "type": "string"
              },
              "literal_sha256": {
                "type": "string"
              }
            },
            "required": [
              "url",
              "source_sha256",
              "locator",
              "captured_at"
            ],
            "additionalProperties": false
          }
        },
        "original_assertion_id": {
          "type": "string"
        },
        "context_guard": {
          "type": "object",
          "properties": {
            "when_all": {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$"
              }
            }
          },
          "required": [
            "when_all"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "id",
        "source",
        "target",
        "predicate",
        "label",
        "assertion_status",
        "authority",
        "scope",
        "provenance"
      ],
      "additionalProperties": false
    },
    "requirement": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        },
        "when_all": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "scope": {
          "type": "string"
        },
        "limitations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "covers": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "required_paths": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/path"
          }
        }
      },
      "required": [
        "id",
        "label",
        "when_all",
        "required",
        "scope"
      ],
      "additionalProperties": false
    },
    "issue": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1
        },
        "message": {
          "type": "string"
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "code",
        "message",
        "ids"
      ],
      "additionalProperties": false
    },
    "path": {
      "type": "object",
      "properties": {
        "seed": {
          "type": "string",
          "minLength": 1
        },
        "assertions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "records": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "seed",
        "assertions",
        "records"
      ],
      "additionalProperties": false
    },
    "bundle": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "snapshot": {
          "type": "string",
          "minLength": 1
        },
        "source_url": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "snapshot",
        "source_url"
      ],
      "additionalProperties": false
    },
    "budget": {
      "type": "object",
      "properties": {
        "max_nodes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200
        },
        "max_relationships": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        },
        "max_depth": {
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        },
        "max_bytes": {
          "type": "integer",
          "minimum": 8192,
          "maximum": 524288
        }
      },
      "required": [
        "max_nodes",
        "max_relationships",
        "max_depth",
        "max_bytes"
      ],
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "properties": {
        "url": {
          "type": "string"
        },
        "source_sha256": {
          "type": "string"
        },
        "locator": {
          "type": "string"
        },
        "captured_at": {
          "type": "string"
        },
        "source_date": {
          "type": "string"
        },
        "source_date_kind": {
          "type": "string"
        },
        "literal_sha256": {
          "type": "string"
        }
      },
      "required": [
        "url",
        "source_sha256",
        "locator",
        "captured_at"
      ],
      "additionalProperties": false
    },
    "discovery_card": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 2000,
          "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
        },
        "label": {
          "type": "string"
        },
        "assertion_status": {
          "enum": [
            "normalized",
            "inferred",
            "model-derived"
          ]
        },
        "authority": {
          "type": "object",
          "properties": {
            "class": {
              "type": "string"
            },
            "label": {
              "type": "string"
            },
            "source": {
              "type": "string"
            }
          },
          "required": [
            "class",
            "label",
            "source"
          ],
          "additionalProperties": false
        },
        "scope": {
          "type": "string"
        },
        "provenance": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string"
              },
              "source_sha256": {
                "type": "string"
              },
              "locator": {
                "type": "string"
              },
              "captured_at": {
                "type": "string"
              },
              "source_date": {
                "type": "string"
              },
              "source_date_kind": {
                "type": "string"
              },
              "literal_sha256": {
                "type": "string"
              }
            },
            "required": [
              "url",
              "source_sha256",
              "locator",
              "captured_at"
            ],
            "additionalProperties": false
          }
        },
        "rights": {
          "type": "string"
        },
        "access": {
          "enum": [
            "public",
            "restricted"
          ]
        },
        "evidence_id": {
          "type": "string",
          "maxLength": 2000,
          "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
        },
        "evidence_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "heading_path": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "maxLength": 500
          }
        },
        "summary": {
          "type": "string",
          "maxLength": 2000
        },
        "search_aliases": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "string",
            "maxLength": 500
          }
        },
        "route_patterns": {
          "type": "array",
          "maxItems": 8,
          "items": { "$ref": "#/$defs/route_pattern" }
        }
      },
      "required": [
        "id",
        "label",
        "assertion_status",
        "authority",
        "scope",
        "provenance",
        "rights",
        "access",
        "evidence_id",
        "evidence_sha256",
        "heading_path",
        "summary",
        "search_aliases"
      ],
      "additionalProperties": false
    },
    "route_pattern": {
      "type": "object",
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,79}$" },
        "scope_group": { "const": 0 },
        "all_of": {
          "type": "array",
          "minItems": 3,
          "maxItems": 4,
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 8,
            "items": { "type": "string", "minLength": 1, "maxLength": 120 }
          }
        }
      },
      "required": ["id", "scope_group", "all_of"],
      "additionalProperties": false
    },
    "discovery_card_reference": {
      "type": "object",
      "properties": {
        "schema": {
          "const": "okf-discovery-card-reference.v1"
        },
        "id": {
          "type": "string",
          "maxLength": 2000,
          "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
        },
        "evidence_id": {
          "type": "string",
          "maxLength": 2000,
          "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
        },
        "card_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "ordinal": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        }
      },
      "required": [
        "schema",
        "id",
        "evidence_id",
        "card_sha256",
        "ordinal"
      ],
      "additionalProperties": false,
      "description": "Bound navigation metadata locator. Select the ordinal from the context-bound manifest discovery inventory, verify its transferred/decoded file and complete card hashes. Complete evidence remains separate."
    },
    "discovery_incident_reference": {
      "type": "object",
      "properties": {
        "schema": {
          "const": "okf-discovery-incident-reference.v1"
        },
        "id": {
          "type": "string",
          "maxLength": 2000,
          "pattern": "^[a-z][a-z0-9+.-]*:[!-~]+$"
        },
        "incident_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "outgoing_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30000
        },
        "incoming_count": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30000
        }
      },
      "required": [
        "schema",
        "id",
        "incident_sha256",
        "outgoing_count",
        "incoming_count"
      ],
      "additionalProperties": false,
      "description": "Exact incident metadata locator. Hash id with the corpus bucket algorithm, read the bound manifest relationship shard and verify the complete entry hash. This is an audit reference, not selected evidence."
    },
    "context_guard_decision": {
      "type": "object",
      "properties": {
        "assertion_id": {
          "type": "string",
          "minLength": 1
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "when_all": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$"
          }
        },
        "missing_concepts": {
          "type": "array",
          "minItems": 0,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$"
          }
        },
        "unavailable_concepts": {
          "type": "array",
          "minItems": 0,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$"
          }
        },
        "status": {
          "enum": [
            "matched",
            "unmatched"
          ]
        }
      },
      "required": [
        "assertion_id",
        "source",
        "target",
        "when_all",
        "missing_concepts",
        "unavailable_concepts",
        "status"
      ],
      "additionalProperties": false
    }
  }
}
