{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://examq.local/schemas/examq-ai-output.schema.json",
  "title": "examq AI output (prompt 1.0)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "version",
    "part",
    "final",
    "questions"
  ],
  "properties": {
    "format": {
      "const": "examq-ai-output"
    },
    "version": {
      "const": "1.0"
    },
    "part": {
      "type": "integer",
      "minimum": 1
    },
    "final": {
      "type": "boolean"
    },
    "bank": {
      "type": "object",
      "properties": {
        "title": {
          "type": "string"
        }
      }
    },
    "questions": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/singleChoiceQuestion"
          },
          {
            "$ref": "#/$defs/multipleChoiceQuestion"
          },
          {
            "$ref": "#/$defs/dragAndDropQuestion"
          },
          {
            "$ref": "#/$defs/shortAnswerQuestion"
          },
          {
            "$ref": "#/$defs/numericQuestion"
          },
          {
            "$ref": "#/$defs/orderingQuestion"
          }
        ]
      }
    },
    "skipped": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "location",
          "reason"
        ],
        "properties": {
          "location": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        }
      }
    }
  },
  "$defs": {
    "baseQuestion": {
      "type": "object",
      "required": [
        "id",
        "type",
        "prompt"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "type": {
          "enum": [
            "single_choice",
            "multiple_choice",
            "drag_and_drop",
            "short_answer",
            "numeric",
            "ordering"
          ]
        },
        "prompt": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "explanation": {
          "type": "string"
        },
        "difficulty": {
          "enum": [
            "easy",
            "medium",
            "hard"
          ]
        },
        "category": {
          "type": "string"
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source": {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "location": {
              "type": "string"
            },
            "flags": {
              "type": "array",
              "uniqueItems": true,
              "items": {
                "enum": [
                  "no-answer-in-source",
                  "uncertain"
                ]
              }
            }
          }
        },
        "extensions": {
          "$ref": "#/$defs/extensions"
        }
      }
    },
    "choice": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "id",
        "text"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "text": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        }
      }
    },
    "singleChoiceQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [
            "choices"
          ],
          "properties": {
            "type": {
              "const": "single_choice"
            },
            "choices": {
              "type": "array",
              "minItems": 2,
              "items": {
                "$ref": "#/$defs/choice"
              }
            },
            "answer": {
              "type": "array",
              "minItems": 1,
              "maxItems": 1,
              "uniqueItems": true,
              "items": {
                "type": "string"
              }
            }
          }
        }
      ]
    },
    "multipleChoiceQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [
            "choices"
          ],
          "properties": {
            "type": {
              "const": "multiple_choice"
            },
            "choices": {
              "type": "array",
              "minItems": 2,
              "items": {
                "$ref": "#/$defs/choice"
              }
            },
            "answer": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "type": "string"
              }
            }
          }
        }
      ]
    },
    "dragAndDropQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [
            "items",
            "targets"
          ],
          "properties": {
            "type": {
              "const": "drag_and_drop"
            },
            "dragLayout": {
              "enum": [
                "mapping",
                "groups"
              ]
            },
            "items": {
              "type": "array",
              "minItems": 1,
              "items": {
                "$ref": "#/$defs/choice"
              }
            },
            "targets": {
              "type": "array",
              "minItems": 1,
              "items": {
                "$ref": "#/$defs/choice"
              }
            },
            "answer": {
              "type": "object",
              "minProperties": 1,
              "additionalProperties": {
                "type": "string"
              }
            }
          }
        }
      ]
    },
    "shortAnswerQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [],
          "properties": {
            "type": {
              "const": "short_answer"
            },
            "answer": {
              "type": "object",
              "required": [
                "accepted"
              ],
              "properties": {
                "accepted": {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 20,
                  "items": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "pattern": "\\S"
                  }
                },
                "caseSensitive": {
                  "type": "boolean"
                },
                "collapseWhitespace": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      ]
    },
    "numericQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [],
          "properties": {
            "type": {
              "const": "numeric"
            },
            "answer": {
              "type": "object",
              "required": [
                "value"
              ],
              "properties": {
                "value": {
                  "type": "number"
                },
                "tolerance": {
                  "type": "number",
                  "minimum": 0
                },
                "toleranceType": {
                  "enum": [
                    "absolute",
                    "percent"
                  ]
                },
                "unit": {
                  "type": "string",
                  "maxLength": 40
                }
              }
            }
          }
        }
      ]
    },
    "orderingQuestion": {
      "allOf": [
        {
          "$ref": "#/$defs/baseQuestion"
        },
        {
          "type": "object",
          "required": [
            "items"
          ],
          "properties": {
            "type": {
              "const": "ordering"
            },
            "items": {
              "type": "array",
              "minItems": 2,
              "items": {
                "$ref": "#/$defs/choice"
              }
            },
            "answer": {
              "type": "array",
              "minItems": 2,
              "uniqueItems": true,
              "items": {
                "type": "string"
              }
            }
          }
        }
      ]
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z0-9-]+(\\.[a-z0-9-]+)+$"
      }
    }
  }
}
