{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chris-page-gov.github.io/okf-explorer/profile/evidence-workbench-passages/v1/case.schema.json",
  "title": "Passage boundary review case",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "id",
    "label",
    "document",
    "pages",
    "before",
    "after",
    "observation",
    "review"
  ],
  "properties": {
    "schema": {
      "const": "okf-passage-boundary-review.v1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._:-]*$"
    },
    "label": {
      "type": "string",
      "minLength": 1
    },
    "document": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "version",
        "pdf",
        "extraction",
        "baseline_sha256",
        "parser"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "family": {
          "type": "string"
        },
        "source_role": {
          "type": "string"
        },
        "pdf": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "url",
            "sha256"
          ],
          "properties": {
            "url": {
              "type": "string"
            },
            "sha256": {
              "$ref": "#/$defs/sha256"
            },
            "repository_path": {
              "type": "string"
            },
            "delivery_url": {
              "type": "string"
            }
          }
        },
        "extraction": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "url",
            "sha256"
          ],
          "properties": {
            "url": {
              "type": "string"
            },
            "sha256": {
              "$ref": "#/$defs/sha256"
            },
            "source_path": {
              "type": "string"
            },
            "source_sha256": {
              "$ref": "#/$defs/sha256"
            }
          }
        },
        "baseline_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "parser": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "version",
            "ruleset_version",
            "settings_sha256",
            "applied_rules"
          ],
          "properties": {
            "version": {
              "type": "string"
            },
            "ruleset_version": {
              "type": "string"
            },
            "settings_sha256": {
              "$ref": "#/$defs/sha256"
            },
            "applied_rules": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "implementation_bindings": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/$defs/sha256"
              },
              "propertyNames": {
                "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.?/)[^\\\\]+$"
              }
            },
            "settings_text": {
              "type": "string",
              "maxLength": 65536
            }
          }
        }
      }
    },
    "pages": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "$ref": "#/$defs/page"
      }
    },
    "before": {
      "$ref": "#/$defs/units"
    },
    "after": {
      "$ref": "#/$defs/units"
    },
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "candidate_bytes_outside_old_passage",
        "covered_once_bytes",
        "old_passage_bytes",
        "scope"
      ],
      "properties": {
        "candidate_bytes_outside_old_passage": {
          "type": "integer",
          "minimum": 0
        },
        "covered_once_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "old_passage_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "scope": {
          "type": "string"
        }
      }
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "method",
        "classification",
        "rationale",
        "uncertainty",
        "source_links"
      ],
      "properties": {
        "method": {
          "type": "string"
        },
        "classification": {
          "type": "string"
        },
        "finding_status": {
          "type": "string"
        },
        "rationale": {
          "type": "string"
        },
        "uncertainty": {
          "type": "string"
        },
        "source_links": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "page",
              "start_utf8",
              "end_utf8",
              "literal",
              "literal_sha256",
              "pdf_url"
            ],
            "properties": {
              "page": {
                "type": "integer",
                "minimum": 1
              },
              "start_utf8": {
                "type": "integer",
                "minimum": 0
              },
              "end_utf8": {
                "type": "integer",
                "minimum": 1
              },
              "literal": {
                "type": "string"
              },
              "literal_sha256": {
                "$ref": "#/$defs/sha256"
              },
              "pdf_url": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status"
      ],
      "properties": {
        "status": {
          "type": "string"
        },
        "specialist_review": {
          "type": "string"
        },
        "legal_answerability": {
          "type": "string"
        }
      }
    },
    "impact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "document_unit_count_before": {
          "type": "integer",
          "minimum": 0
        },
        "document_unit_count_after": {
          "type": "integer",
          "minimum": 0
        },
        "corpus_unit_count_before": {
          "type": "integer",
          "minimum": 0
        },
        "corpus_unit_count_after": {
          "type": "integer",
          "minimum": 0
        },
        "dependencies": {
          "$ref": "#/$defs/strings"
        },
        "discovery_records": {
          "$ref": "#/$defs/strings"
        },
        "question_packages": {
          "$ref": "#/$defs/strings"
        },
        "budget_omissions": {
          "$ref": "#/$defs/strings"
        }
      }
    },
    "successor_after": {
      "$ref": "#/$defs/units"
    },
    "technical_outcome": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "target_boundary",
        "rationale",
        "residual_structural_findings",
        "legal_answerability"
      ],
      "properties": {
        "status": {
          "enum": [
            "corrected",
            "partial",
            "unresolved"
          ]
        },
        "target_boundary": {
          "enum": [
            "corrected",
            "partial",
            "unresolved"
          ]
        },
        "rationale": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2000
        },
        "residual_structural_findings": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "legal_answerability": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        }
      }
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "strings": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "page": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "number",
        "start_utf8",
        "end_utf8"
      ],
      "properties": {
        "number": {
          "type": "integer",
          "minimum": 1
        },
        "start_utf8": {
          "type": "integer",
          "minimum": 0
        },
        "end_utf8": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "span": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "page",
        "start_utf8",
        "end_utf8"
      ],
      "properties": {
        "page": {
          "type": "integer",
          "minimum": 1
        },
        "start_utf8": {
          "type": "integer",
          "minimum": 0
        },
        "end_utf8": {
          "type": "integer",
          "minimum": 1
        },
        "literal_sha256": {
          "$ref": "#/$defs/sha256"
        }
      }
    },
    "units": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "$ref": "#/$defs/unit"
      }
    },
    "unit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "role",
        "paragraph_labels",
        "spans",
        "joiner",
        "text_sha256"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "role": {
          "type": "string",
          "minLength": 1
        },
        "paragraph_labels": {
          "$ref": "#/$defs/strings"
        },
        "spans": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/span"
          }
        },
        "joiner": {
          "type": "string",
          "maxLength": 10,
          "pattern": "^[\\t\\n\\r ]*$"
        },
        "text_sha256": {
          "$ref": "#/$defs/sha256"
        },
        "text": {
          "type": "string"
        },
        "text_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "boundary_status": {
          "type": "string"
        },
        "completeness": {
          "type": "string"
        }
      }
    }
  }
}
