{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Interview Test Definition",
  "description": "Schema for test JSON files uploaded to the Interview Test Platform. See docs/02-test-definition-and-management.md for the full rules, including cross-field checks a JSON Schema can't express on its own — the backend also enforces: question ids and option ids must be unique within their scope, `correct` must reference option ids that actually exist, and a single-correct question (multi_correct: false) may list at most one correct id.",
  "type": "object",
  "required": ["title", "time_limit_seconds", "questions"],
  "additionalProperties": false,
  "properties": {
    "test_id": {
      "type": "string",
      "description": "Optional. A UUID is generated on import if omitted."
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "time_limit_seconds": {
      "type": "integer",
      "minimum": 1,
      "description": "Total time budget for the candidate's one attempt, in seconds."
    },
    "max_attempts": {
      "type": "integer",
      "minimum": 1,
      "default": 2,
      "description": "Reserved for a future admin-granted-retry feature. Does not currently let a candidate retake a finished test — see docs/03-session-lifecycle.md."
    },
    "questions": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/definitions/question" }
    }
  },
  "definitions": {
    "question": {
      "oneOf": [
        { "$ref": "#/definitions/multiOptionQuestion" },
        { "$ref": "#/definitions/freeTextQuestion" }
      ]
    },
    "multiOptionQuestion": {
      "type": "object",
      "required": ["id", "type", "prompt", "options", "multi_correct", "correct"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1, "description": "Unique within the test." },
        "type": { "const": "multi_option" },
        "prompt": { "type": "string", "minLength": 1 },
        "options": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["id", "text"],
            "additionalProperties": false,
            "properties": {
              "id": { "type": "string", "minLength": 1, "description": "Unique within this question." },
              "text": { "type": "string" }
            }
          }
        },
        "multi_correct": {
          "type": "boolean",
          "description": "false = single-answer (radio button behavior), true = multi-answer (checkbox behavior)."
        },
        "correct": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Option ids that are correct. Always an array, even for a single-correct question."
        }
      }
    },
    "freeTextQuestion": {
      "type": "object",
      "required": ["id", "type", "prompt"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1, "description": "Unique within the test." },
        "type": { "const": "free_text" },
        "prompt": { "type": "string", "minLength": 1 },
        "max_length": {
          "type": "integer",
          "minimum": 1,
          "default": 5000,
          "description": "Character cap on the answer."
        }
      }
    }
  }
}
