{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/wsxjs/quizerjs/schema/quiz-dsl.json",
  "title": "Quiz DSL Schema",
  "description": "Quiz DSL (Domain Specific Language) schema for quizerjs",
  "type": "object",
  "required": ["version", "quiz"],
  "properties": {
    "version": {
      "type": "string",
      "description": "DSL version number",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "quiz": {
      "type": "object",
      "required": ["id", "title", "questions"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Quiz unique identifier"
        },
        "title": {
          "type": "string",
          "description": "Quiz title"
        },
        "description": {
          "type": "string",
          "description": "Quiz description"
        },
        "metadata": {
          "type": "object",
          "properties": {
            "author": {
              "type": "string"
            },
            "createdAt": {
              "type": "string",
              "format": "date-time"
            },
            "updatedAt": {
              "type": "string",
              "format": "date-time"
            },
            "tags": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "additionalProperties": true
        },
        "settings": {
          "type": "object",
          "properties": {
            "allowRetry": {
              "type": "boolean"
            },
            "showResults": {
              "type": "boolean"
            },
            "timeLimit": {
              "type": "number",
              "minimum": 0
            },
            "randomizeQuestions": {
              "type": "boolean"
            },
            "randomizeOptions": {
              "type": "boolean"
            },
            "passingScore": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            }
          }
        },
        "questions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "oneOf": [
              {
                "$ref": "#/definitions/singleChoiceQuestion"
              },
              {
                "$ref": "#/definitions/multipleChoiceQuestion"
              },
              {
                "$ref": "#/definitions/textInputQuestion"
              },
              {
                "$ref": "#/definitions/trueFalseQuestion"
              }
            ]
          }
        }
      }
    }
  },
  "definitions": {
    "singleChoiceQuestion": {
      "type": "object",
      "required": ["id", "type", "text", "options"],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": ["single_choice"]
        },
        "text": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/definitions/option"
          }
        },
        "points": {
          "type": "number",
          "minimum": 0
        },
        "explanation": {
          "type": "string"
        },
        "metadata": {
          "$ref": "#/definitions/questionMetadata"
        }
      }
    },
    "multipleChoiceQuestion": {
      "type": "object",
      "required": ["id", "type", "text", "options"],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": ["multiple_choice"]
        },
        "text": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/definitions/option"
          }
        },
        "points": {
          "type": "number",
          "minimum": 0
        },
        "explanation": {
          "type": "string"
        },
        "metadata": {
          "$ref": "#/definitions/questionMetadata"
        }
      }
    },
    "textInputQuestion": {
      "type": "object",
      "required": ["id", "type", "text", "correctAnswer"],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": ["text_input"]
        },
        "text": {
          "type": "string"
        },
        "correctAnswer": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            }
          ]
        },
        "caseSensitive": {
          "type": "boolean"
        },
        "points": {
          "type": "number",
          "minimum": 0
        },
        "explanation": {
          "type": "string"
        },
        "metadata": {
          "$ref": "#/definitions/questionMetadata"
        }
      }
    },
    "trueFalseQuestion": {
      "type": "object",
      "required": ["id", "type", "text", "correctAnswer"],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": ["true_false"]
        },
        "text": {
          "type": "string"
        },
        "correctAnswer": {
          "type": "boolean"
        },
        "points": {
          "type": "number",
          "minimum": 0
        },
        "explanation": {
          "type": "string"
        },
        "metadata": {
          "$ref": "#/definitions/questionMetadata"
        }
      }
    },
    "option": {
      "type": "object",
      "required": ["id", "text", "isCorrect"],
      "properties": {
        "id": {
          "type": "string"
        },
        "text": {
          "type": "string"
        },
        "isCorrect": {
          "type": "boolean"
        }
      }
    },
    "questionMetadata": {
      "type": "object",
      "properties": {
        "difficulty": {
          "type": "string",
          "enum": ["easy", "medium", "hard"]
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": true
    }
  }
}
