{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pipelinexlab.com/contracts/document-content-closure.v1.schema.json",
  "title": "Selected document content closure V1",
  "description": "Shape only. Core verifies all and only reachable parents, kind-directed ancestry, exact canonical material identity and alignment. Source Report provenance grants no destination authority.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "kind",
    "roots",
    "contents"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "kind": {
      "const": "document-content-closure"
    },
    "roots": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/digest"
      }
    },
    "contents": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/descriptor"
      }
    }
  },
  "$defs": {
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "semanticKey": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$"
    },
    "reportTarget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scope",
        "reportKey",
        "revisionRef"
      ],
      "properties": {
        "scope": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "workspaceKey",
            "projectKey"
          ],
          "properties": {
            "kind": {
              "const": "project"
            },
            "workspaceKey": {
              "$ref": "#/$defs/semanticKey"
            },
            "projectKey": {
              "$ref": "#/$defs/semanticKey"
            }
          }
        },
        "reportKey": {
          "$ref": "#/$defs/semanticKey"
        },
        "revisionRef": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "descriptor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "contentRef",
        "kind",
        "size",
        "dependencies"
      ],
      "properties": {
        "contentRef": {
          "$ref": "#/$defs/digest"
        },
        "kind": {
          "enum": [
            "pdf",
            "analysis",
            "citation",
            "translation"
          ]
        },
        "size": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "sourceReport": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/reportTarget"
            }
          ]
        },
        "dependencies": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/digest"
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "pdf"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "sourceReport"
            ],
            "properties": {
              "sourceReport": {
                "$ref": "#/$defs/reportTarget"
              },
              "dependencies": {
                "maxItems": 0,
                "type": "array"
              }
            }
          },
          "else": {
            "properties": {
              "sourceReport": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "analysis"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "properties": {
              "dependencies": {
                "minItems": 1,
                "maxItems": 1,
                "type": "array"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [
                  "citation",
                  "translation"
                ]
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "properties": {
              "dependencies": {
                "minItems": 2,
                "maxItems": 2,
                "type": "array"
              }
            }
          }
        }
      ]
    }
  }
}
