{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Maintenance answer v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "answer_id",
    "status",
    "corpus_revision",
    "model_revision",
    "prompt_revision",
    "statements",
    "review_status"
  ],
  "properties": {
    "schema_version": {
      "const": "maintenance-answer/1"
    },
    "answer_id": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "enum": [
        "answered",
        "insufficient_evidence",
        "conflicting_evidence",
        "needs_review"
      ]
    },
    "corpus_revision": {
      "type": "string",
      "minLength": 1
    },
    "model_revision": {
      "type": "string",
      "minLength": 1
    },
    "prompt_revision": {
      "type": "string",
      "minLength": 1
    },
    "review_status": {
      "enum": [
        "pending",
        "accepted",
        "rejected"
      ]
    },
    "statements": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "text",
          "evidence"
        ],
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1
          },
          "evidence": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "source_id",
                "document_version",
                "sha256",
                "page_index",
                "quote",
                "locator"
              ],
              "properties": {
                "source_id": {
                  "type": "string",
                  "minLength": 1
                },
                "document_version": {
                  "type": "string",
                  "minLength": 1
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                "page_index": {
                  "type": "integer",
                  "minimum": 1
                },
                "quote": {
                  "type": "string",
                  "minLength": 1
                },
                "locator": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "kind",
                    "item_id"
                  ],
                  "properties": {
                    "kind": {
                      "enum": [
                        "text",
                        "table"
                      ]
                    },
                    "item_id": {
                      "type": "string",
                      "minLength": 1
                    },
                    "row": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "column": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "bbox": {
                      "type": "array",
                      "items": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 1
                      },
                      "minItems": 4,
                      "maxItems": 4
                    }
                  },
                  "allOf": [
                    {
                      "if": {
                        "properties": {
                          "kind": {
                            "const": "table"
                          }
                        }
                      },
                      "then": {
                        "required": [
                          "row",
                          "column"
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "answered"
          }
        }
      },
      "then": {
        "properties": {
          "statements": {
            "minItems": 1
          }
        }
      },
      "else": {
        "properties": {
          "statements": {
            "maxItems": 0
          },
          "review_status": {
            "const": "pending"
          }
        }
      }
    }
  ]
}
