{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/MuhammadMoustafa/laser_pointer/main/protocol/library.schema.json",
  "title": "Laser Pointer library",
  "description": "Stored and shared .laser JSON document. Maximum UTF-8 file size: 1048576 bytes. Reader also applies audience normalization, UTF-16 length checks, folder character rules and case-insensitive uniqueness; JSON Schema cannot express all of these. Unknown fields are ignored.",
  "x-maxBytes": 1048576,
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": "laser-pointer-library"
    },
    "version": {
      "const": 1
    },
    "folders": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "$ref": "#/$defs/folder",
        "minLength": 1,
        "type": "string"
      }
    },
    "items": {
      "type": "array",
      "maxItems": 200,
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/poll"
          },
          {
            "$ref": "#/$defs/quiz"
          },
          {
            "$ref": "#/$defs/openAnswers"
          }
        ]
      }
    }
  },
  "required": [
    "format",
    "version",
    "folders",
    "items"
  ],
  "$defs": {
    "folder": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 0,
      "maxLength": 60,
      "description": "Trimmed folder name, at most 60 Unicode scalars; valid result-folder characters. Empty means no folder on a shared item."
    },
    "question": {
      "type": "string",
      "minLength": 1,
      "maxLength": 280,
      "description": "Nonempty after audience text cleaning. Limits count UTF-16 units; raw input ceiling is twice the cap, and trimmed source must also fit. A poll or quiz question may contain line breaks (the JSON escape \\n, at most 4, counted as characters); a title or prompt is one line. In a quiz, text follows the activity text format (docs/quiz-library.md): Markdown **bold**, *italic*, `code`, ^sup^, ~sub~ and $math$, ~~strike~~, styled spans [text]{color=\"#RRGGBB\" background=\"#RRGGBB\" .highlight .underline .smallcaps size=\"0.5\" to \"2\"}, and a backslash before any ASCII punctuation to show it as typed."
    },
    "optionText": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "description": "A poll or quiz option may contain line breaks (the JSON escape \\n, at most 4, counted as characters). In a quiz, text follows the activity text format (docs/quiz-library.md): Markdown **bold**, *italic*, `code`, ^sup^, ~sub~ and $math$, ~~strike~~, styled spans [text]{color=\"#RRGGBB\" background=\"#RRGGBB\" .highlight .underline .smallcaps size=\"0.5\" to \"2\"}, and a backslash before any ASCII punctuation to show it as typed."
    },
    "poll": {
      "type": "object",
      "properties": {
        "question": {
          "$ref": "#/$defs/question"
        },
        "folder": {
          "$ref": "#/$defs/folder"
        },
        "kind": {
          "const": "poll"
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "maxItems": 10,
          "items": {
            "$ref": "#/$defs/optionText"
          },
          "uniqueItems": true
        },
        "multiple": {
          "type": "boolean"
        },
        "named": {
          "type": "boolean"
        },
        "live": {
          "type": "boolean",
          "default": true
        },
        "reveal": {
          "type": "boolean",
          "default": false
        },
        "seconds": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 3600,
          "default": 0
        }
      },
      "required": [
        "question",
        "options",
        "multiple",
        "named"
      ]
    },
    "quizOption": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 32,
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "text": {
          "$ref": "#/$defs/optionText"
        },
        "correct": {
          "type": "boolean",
          "default": false
        },
        "note": {
          "type": "string",
          "maxLength": 1000,
          "default": "",
          "description": "Notes also take lists and links. In a quiz, text follows the activity text format (docs/quiz-library.md): Markdown **bold**, *italic*, `code`, ^sup^, ~sub~ and $math$, ~~strike~~, styled spans [text]{color=\"#RRGGBB\" background=\"#RRGGBB\" .highlight .underline .smallcaps size=\"0.5\" to \"2\"}, and a backslash before any ASCII punctuation to show it as typed."
        }
      },
      "required": [
        "id",
        "text"
      ]
    },
    "quizQuestion": {
      "type": "object",
      "properties": {
        "question": {
          "$ref": "#/$defs/question"
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "maxItems": 10,
          "items": {
            "$ref": "#/$defs/quizOption"
          }
        },
        "multiple": {
          "type": "boolean",
          "default": false
        },
        "multiplier": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10,
          "default": 1
        },
        "penalty": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000,
          "default": 0
        },
        "timeLimit": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 5,
          "maximum": 240
        },
        "readTime": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30
        },
        "keepOrder": {
          "type": "boolean"
        },
        "showCount": {
          "type": "boolean"
        }
      },
      "required": [
        "question",
        "options"
      ],
      "description": "Unique option IDs and distinct cleaned option texts ignoring case. At least one correct answer; exactly one unless multiple is true. Missing overrides inherit quiz settings.",
      "allOf": [
        {
          "if": {
            "properties": {
              "multiple": {
                "const": true
              }
            },
            "required": [
              "multiple"
            ]
          },
          "then": {
            "properties": {
              "options": {
                "contains": {
                  "properties": {
                    "correct": {
                      "const": true
                    }
                  },
                  "required": [
                    "correct"
                  ]
                },
                "minContains": 1
              }
            }
          },
          "else": {
            "properties": {
              "options": {
                "contains": {
                  "properties": {
                    "correct": {
                      "const": true
                    }
                  },
                  "required": [
                    "correct"
                  ]
                },
                "minContains": 1,
                "maxContains": 1
              }
            }
          }
        }
      ]
    },
    "quizSettings": {
      "type": "object",
      "properties": {
        "basePoints": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000,
          "default": 100
        },
        "partialCredit": {
          "type": "boolean",
          "default": true
        },
        "speedScoring": {
          "type": "boolean",
          "default": false
        },
        "timeLimit": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 5,
          "maximum": 240,
          "default": 10
        },
        "readTime": {
          "type": "integer",
          "minimum": 0,
          "maximum": 30,
          "default": 5
        },
        "autoLock": {
          "type": "boolean",
          "default": false
        },
        "optionOrder": {
          "type": "string",
          "enum": [
            "written",
            "sharedShuffle",
            "perPhoneShuffle"
          ],
          "default": "written"
        },
        "showCount": {
          "type": "boolean",
          "default": false
        },
        "leaderboard": {
          "type": "string",
          "enum": [
            "always",
            "end",
            "never"
          ],
          "default": "always"
        },
        "afterQuestion": {
          "type": "string",
          "enum": [
            "nothing",
            "top3",
            "full"
          ],
          "default": "nothing"
        },
        "review": {
          "type": "string",
          "enum": [
            "off",
            "screen",
            "download"
          ],
          "default": "screen"
        },
        "screenNotes": {
          "type": "boolean",
          "default": true
        }
      },
      "required": [],
      "allOf": [
        {
          "if": {
            "properties": {
              "speedScoring": {
                "const": true
              }
            },
            "required": [
              "speedScoring"
            ]
          },
          "then": {
            "properties": {
              "timeLimit": {
                "type": "integer"
              }
            }
          }
        }
      ]
    },
    "quiz": {
      "type": "object",
      "properties": {
        "question": {
          "$ref": "#/$defs/question"
        },
        "folder": {
          "$ref": "#/$defs/folder"
        },
        "kind": {
          "const": "quiz"
        },
        "questions": {
          "type": "array",
          "maxItems": 50,
          "items": {
            "$ref": "#/$defs/quizQuestion"
          }
        },
        "settings": {
          "$ref": "#/$defs/quizSettings",
          "default": {}
        }
      },
      "required": [
        "kind",
        "question",
        "questions"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "settings": {
                "properties": {
                  "speedScoring": {
                    "const": true
                  }
                },
                "required": [
                  "speedScoring"
                ]
              }
            },
            "required": [
              "settings"
            ]
          },
          "then": {
            "properties": {
              "questions": {
                "items": {
                  "properties": {
                    "timeLimit": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    },
    "openAnswers": {
      "type": "object",
      "properties": {
        "question": {
          "$ref": "#/$defs/question"
        },
        "folder": {
          "$ref": "#/$defs/folder"
        },
        "kind": {
          "const": "open_answers"
        },
        "display": {
          "type": "string",
          "enum": [
            "wall",
            "oneByOne",
            "cloud"
          ],
          "default": "wall"
        },
        "answersPerGuest": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "maximum": 1000,
          "default": 1
        },
        "length": {
          "type": "string",
          "enum": [
            "short",
            "long"
          ],
          "default": "long",
          "description": "Default short (25 UTF-16 units) for cloud, otherwise long (280).",
          "x-answerCharacters": {
            "short": 25,
            "long": 280
          }
        },
        "anonymous": {
          "type": "boolean",
          "default": true
        },
        "autoApproval": {
          "type": "boolean",
          "default": true
        }
      },
      "required": [
        "kind",
        "question"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "display": {
                "const": "cloud"
              }
            },
            "required": [
              "display"
            ]
          },
          "then": {
            "properties": {
              "length": {
                "default": "short"
              }
            }
          }
        }
      ]
    }
  }
}
