{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Banco de preguntas Preguntario v1",
  "description": "Además del esquema, la aplicación valida ids únicos, referencia correcta y alternativesToShow <= alternatives.length.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "title", "questions"],
  "properties": {
    "version": { "const": 1 },
    "title": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "\\S" },
    "description": { "type": "string", "minLength": 1, "maxLength": 2000, "pattern": "\\S" },
    "mathFormat": { "$ref": "#/$defs/mathFormat", "description": "Notación predeterminada del banco. Si se omite, latex." },
    "tags": { "type": "array", "maxItems": 20, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 50, "pattern": "\\S" } },
    "questions": {
      "type": "array", "minItems": 1, "maxItems": 10000,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["id", "question", "alternatives", "correctAnswerId", "explanation"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "subject": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "\\S" },
          "mathFormat": { "$ref": "#/$defs/mathFormat", "description": "Sobrescribe la notación del banco para esta pregunta completa." },
          "variantGroup": { "$ref": "#/$defs/id", "description": "Las preguntas con el mismo grupo cuentan como una. Se elige una variante por sesión." },
          "question": { "type": "string", "minLength": 1, "maxLength": 10000, "pattern": "\\S" },
          "alternativesToShow": { "type": "integer", "minimum": 2, "maximum": 50 },
          "alternatives": {
            "type": "array", "minItems": 2, "maxItems": 50,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["id", "text"],
              "properties": {
                "id": { "$ref": "#/$defs/id" },
                "text": { "type": "string", "minLength": 1, "maxLength": 4000, "pattern": "\\S" }
              }
            }
          },
          "correctAnswerId": { "$ref": "#/$defs/id" },
          "explanation": { "type": "string", "minLength": 1, "maxLength": 10000, "pattern": "\\S" }
        }
      }
    }
  },
  "$defs": {
    "id": { "type": "string", "minLength": 1, "maxLength": 120, "pattern": "\\S" },
    "mathFormat": { "enum": ["latex", "typst"] }
  }
}
