{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "AIRA Learn course package v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "course",
    "papers"
  ],
  "properties": {
    "schema_version": {
      "const": 1
    },
    "course": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "college": {
          "type": "string",
          "maxLength": 256
        },
        "category": {
          "type": "string",
          "maxLength": 128
        },
        "credits": {
          "type": "number",
          "minimum": 0,
          "maximum": 99,
          "multipleOf": 0.1
        },
        "description": {
          "type": "string"
        }
      }
    },
    "papers": {
      "type": "array",
      "maxItems": 20,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "questions"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 200,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "question_type",
                "test",
                "answer"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$"
                },
                "question_type": {
                  "enum": [
                    "singleChoice",
                    "multipleChoice",
                    "trueOrFalse",
                    "fillBlanks",
                    "shortAnswer",
                    "calculation",
                    "proof",
                    "caseAnalysis",
                    "programming",
                    "originalQuestion"
                  ]
                },
                "test": {
                  "type": "string",
                  "minLength": 1
                },
                "answer": {
                  "type": "string",
                  "minLength": 1
                },
                "explanation": {
                  "type": "string"
                },
                "score": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1000,
                  "multipleOf": 0.01
                },
                "options": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "option",
                      "text"
                    ],
                    "properties": {
                      "option": {
                        "type": "string",
                        "pattern": "^[A-H]$"
                      },
                      "text": {
                        "type": "string",
                        "minLength": 1
                      }
                    }
                  }
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "question_type": {
                        "enum": [
                          "singleChoice",
                          "multipleChoice"
                        ]
                      }
                    }
                  },
                  "then": {
                    "required": [
                      "options"
                    ],
                    "properties": {
                      "options": {
                        "minItems": 2
                      }
                    }
                  },
                  "else": {
                    "properties": {
                      "options": {
                        "maxItems": 0
                      }
                    }
                  }
                },
                {
                  "if": {
                    "properties": {
                      "question_type": {
                        "const": "singleChoice"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "pattern": "^[A-H]$"
                      }
                    }
                  }
                },
                {
                  "if": {
                    "properties": {
                      "question_type": {
                        "const": "multipleChoice"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "pattern": "^\\s*[A-H](\\s*,\\s*[A-H]){1,7}\\s*$"
                      }
                    }
                  }
                },
                {
                  "if": {
                    "properties": {
                      "question_type": {
                        "const": "trueOrFalse"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "enum": [
                          "T",
                          "F"
                        ]
                      }
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
