{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://autoqa.example/schemas/case-input.schema.json",
  "title": "AutoQA Case Input",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "documentType",
    "schemaVersion",
    "caseId",
    "createdAt",
    "contractRef",
    "task",
    "evidenceBundle",
    "attempt",
    "caseTags"
  ],
  "properties": {
    "documentType": {
      "const": "case_input"
    },
    "schemaVersion": {
      "$ref": "common.schema.json#/$defs/SemVer"
    },
    "caseId": {
      "$ref": "common.schema.json#/$defs/Identifier"
    },
    "createdAt": {
      "$ref": "common.schema.json#/$defs/DateTime"
    },
    "contractRef": {
      "$ref": "common.schema.json#/$defs/ContractRef"
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "taskId",
        "taskType",
        "prompt",
        "contentHash"
      ],
      "properties": {
        "taskId": {
          "$ref": "common.schema.json#/$defs/Identifier"
        },
        "taskType": {
          "type": "string",
          "minLength": 1
        },
        "prompt": {
          "type": "string",
          "minLength": 1
        },
        "taskInstructions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "expectedOutputFormat": {
          "type": "string"
        },
        "contentHash": {
          "$ref": "common.schema.json#/$defs/ContentHash"
        },
        "metadata": {
          "type": "object",
          "additionalProperties": true
        }
      }
    },
    "evidenceBundle": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "evidenceId",
          "evidenceClassId",
          "title",
          "content",
          "contentHash",
          "authorityRank",
          "permitted",
          "capturedAt"
        ],
        "properties": {
          "evidenceId": {
            "$ref": "common.schema.json#/$defs/Identifier"
          },
          "evidenceClassId": {
            "$ref": "common.schema.json#/$defs/Identifier"
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "content": {
            "type": "string",
            "minLength": 1
          },
          "contentHash": {
            "$ref": "common.schema.json#/$defs/ContentHash"
          },
          "sourceUri": {
            "type": "string",
            "format": "uri"
          },
          "authorityRank": {
            "type": "integer",
            "minimum": 0
          },
          "permitted": {
            "type": "boolean"
          },
          "publishedAt": {
            "$ref": "common.schema.json#/$defs/DateTime"
          },
          "capturedAt": {
            "$ref": "common.schema.json#/$defs/DateTime"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "attempt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "attemptId",
        "content",
        "contentHash",
        "submittedAt"
      ],
      "properties": {
        "attemptId": {
          "$ref": "common.schema.json#/$defs/Identifier"
        },
        "authorId": {
          "$ref": "common.schema.json#/$defs/Identifier"
        },
        "content": {
          "type": "string"
        },
        "contentHash": {
          "$ref": "common.schema.json#/$defs/ContentHash"
        },
        "submittedAt": {
          "$ref": "common.schema.json#/$defs/DateTime"
        },
        "attachments": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "artifactId",
              "artifactType",
              "contentHash"
            ],
            "properties": {
              "artifactId": {
                "$ref": "common.schema.json#/$defs/Identifier"
              },
              "artifactType": {
                "type": "string"
              },
              "content": {
                "type": "string"
              },
              "contentHash": {
                "$ref": "common.schema.json#/$defs/ContentHash"
              }
            }
          }
        },
        "toolTraces": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "traceId",
              "toolName",
              "input",
              "output",
              "contentHash"
            ],
            "properties": {
              "traceId": {
                "$ref": "common.schema.json#/$defs/Identifier"
              },
              "toolName": {
                "type": "string"
              },
              "input": {},
              "output": {},
              "contentHash": {
                "$ref": "common.schema.json#/$defs/ContentHash"
              }
            }
          }
        }
      }
    },
    "humanReview": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "annotationId",
        "reviewerId",
        "label",
        "reasonCodes",
        "rationale",
        "submittedAt"
      ],
      "properties": {
        "annotationId": {
          "$ref": "common.schema.json#/$defs/Identifier"
        },
        "reviewerId": {
          "$ref": "common.schema.json#/$defs/Identifier"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "score": {
          "type": "number"
        },
        "reasonCodes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "rationale": {
          "type": "string"
        },
        "criterionAnnotations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "criterionId",
              "verdict",
              "rationale"
            ],
            "properties": {
              "criterionId": {
                "$ref": "common.schema.json#/$defs/Identifier"
              },
              "verdict": {
                "$ref": "common.schema.json#/$defs/CriterionVerdict"
              },
              "severity": {
                "$ref": "common.schema.json#/$defs/Severity"
              },
              "rationale": {
                "type": "string"
              },
              "citedSpans": {
                "type": "array",
                "items": {
                  "$ref": "common.schema.json#/$defs/SpanRef"
                }
              }
            }
          }
        },
        "reviewerConfidence": {
          "$ref": "common.schema.json#/$defs/Confidence"
        },
        "submittedAt": {
          "$ref": "common.schema.json#/$defs/DateTime"
        }
      }
    },
    "referenceAnswers": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "referenceId",
          "role",
          "content",
          "contentHash"
        ],
        "properties": {
          "referenceId": {
            "$ref": "common.schema.json#/$defs/Identifier"
          },
          "role": {
            "type": "string",
            "enum": [
              "authoritative",
              "illustrative",
              "positive_anchor",
              "negative_anchor"
            ]
          },
          "content": {
            "type": "string"
          },
          "contentHash": {
            "$ref": "common.schema.json#/$defs/ContentHash"
          }
        }
      }
    },
    "declaredExpectedElements": {
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/ExpectedElement"
      }
    },
    "caseTags": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string"
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true
    }
  }
}
