{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "version", "title", "source", "capabilities", "units", "lessons", "materials"],
  "properties": {
    "schemaVersion": { "const": 1 },
    "id": { "$ref": "#/definitions/id" },
    "version": { "type": "integer", "minimum": 1, "maximum": 1000000 },
    "title": { "$ref": "#/definitions/label" },
    "cover": { "$ref": "#/definitions/asset" },
    "inputPolicy": { "$ref": "#/definitions/inputPolicy" },
    "answerInput": { "$ref": "#/definitions/answerInput" },
    "description": { "type": "string", "maxLength": 2000 },
    "learningObjectives": { "$ref": "#/definitions/learningObjectives" },
    "grades": { "type": "array", "minItems": 1, "maxItems": 12, "uniqueItems": true, "items": { "type": "integer", "minimum": 1, "maximum": 12 } },
    "trialLessons": { "type": "integer", "minimum": 0, "maximum": 100 },
    "clientSupport": { "$ref": "#/definitions/clientSupport" },
    "upgrade": { "$ref": "#/definitions/upgrade" },
    "source": { "$ref": "#/definitions/label" },
    "attributions": {
      "type": "array", "minItems": 1, "maxItems": 10,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["name", "url", "license", "licenseURL", "revision", "changes"],
        "properties": {
          "name": { "$ref": "#/definitions/label" },
          "url": { "$ref": "#/definitions/httpsURL" },
          "license": { "$ref": "#/definitions/label" },
          "licenseURL": { "$ref": "#/definitions/httpsURL" },
          "revision": { "$ref": "#/definitions/label" },
          "changes": { "type": "string", "minLength": 1, "maxLength": 2000 }
        }
      }
    },
    "subject": { "enum": ["english", "math", "chinese", "other"] },
    "mode": { "enum": ["lessons", "vocabulary"] },
    "dailyLessonLimit": { "const": 1 },
    "sourceDocument": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "pageCount",
        "questionCount",
        "coverage",
        "omitted"
      ],
      "properties": {
        "pageCount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20
        },
        "questionCount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "coverage": {
          "enum": [
            "complete",
            "partial"
          ]
        },
        "omitted": {
          "type": "array",
          "maxItems": 400,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "page",
              "label",
              "prompt",
              "reason"
            ],
            "properties": {
              "id": {
                "$ref": "#/definitions/id"
              },
              "page": {
                "type": "integer",
                "minimum": 1,
                "maximum": 20
              },
              "label": {
                "$ref": "#/definitions/label"
              },
              "prompt": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2000
              },
              "reason": {
                "$ref": "#/definitions/label"
              }
            }
          }
        }
      }
    },
    "studyItems": {
      "type": "array", "maxItems": 10000,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["id", "kind", "title", "content", "lessonIDs"],
        "properties": {
          "id": { "$ref": "#/definitions/id" },
          "kind": { "enum": ["vocabulary", "knowledge"] },
          "title": { "$ref": "#/definitions/label" },
          "content": { "type": "string", "minLength": 1, "maxLength": 2000 },
          "blocks": {
            "type": "array", "minItems": 1, "maxItems": 40,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["kind", "text"],
              "properties": {
                "kind": { "enum": ["heading", "paragraph", "example", "note"] },
                "text": { "type": "string", "minLength": 1, "maxLength": 2000 },
                "translation": { "type": "string", "minLength": 1, "maxLength": 2000 },
                "emphasis": { "type": "array", "maxItems": 16, "uniqueItems": true,
                  "items": { "type": "string", "minLength": 1, "maxLength": 2000 } }
              }
            }
          },
          "example": { "$ref": "#/definitions/label" },
          "exampleTranslation": { "$ref": "#/definitions/label" },
          "media": {
            "type": "object", "additionalProperties": false, "minProperties": 1,
            "properties": {
              "image": { "$ref": "#/definitions/asset" },
              "imageMeaning": { "$ref": "#/definitions/label" },
              "pronunciationUK": { "$ref": "#/definitions/asset" },
              "pronunciationUS": { "$ref": "#/definitions/asset" },
              "exampleAudio": { "$ref": "#/definitions/asset" }
            }
          },
          "phonetics": {
            "type": "object", "additionalProperties": false, "minProperties": 1,
            "properties": {
              "us": { "type": "string", "minLength": 1, "maxLength": 200 },
              "uk": { "type": "string", "minLength": 1, "maxLength": 200 }
            }
          },
          "knowledgePointIDs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } },
          "lessonIDs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/definitions/id" } }
        }
      }
    },
    "access": { "enum": ["free", "restricted"] },
    "reviewPolicy": {
      "type": "object", "additionalProperties": false, "required": ["delayDays", "questionCount"],
      "properties": {
        "delayDays": { "type": "integer", "minimum": 1, "maximum": 90 },
        "questionCount": { "type": "integer", "minimum": 1, "maximum": 5 }
      }
    },
    "capabilities": {
      "type": "array", "uniqueItems": true,
      "items": { "enum": ["singleChoice@1", "multipleChoice@1", "text@1", "wordOrder@1", "passage@1", "image@1", "audio@1", "separatePractice@1", "unitSchedule@1", "spacedReview@1", "readingSupport@1", "materialNarration@1", "continuousVocabulary@1", "studyMedia@1", "studyBlocks@1", "courseCover@1", "answerInput@1", "answerInput@2", "challengeGroups@1", "supplementalLessons@1", "weeklyUnit@1", "practiceGroups@1", "mergedLessons@1", "questionOrder@1", "sourceDocument@1", "materialAssets@1", "video@1", "videoLinear@1", "listeningTranscript@1", "mathInteraction@1", "structuredResponse@1", "numericResponse@1"] }
    },
    "units": {
      "type": "array", "maxItems": 100,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["id", "title", "lessonIDs"],
        "properties": {
          "id": { "$ref": "#/definitions/id" }, "title": { "$ref": "#/definitions/label" },
          "lessonIDs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } }
        }
      }
    },
    "lessons": {
      "type": "array", "maxItems": 200,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["id", "title", "prerequisiteIDs", "questions"],
        "properties": {
          "id": { "$ref": "#/definitions/id" }, "title": { "$ref": "#/definitions/label" },
          "prerequisiteIDs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/definitions/id" } },
          "learningObjectives": { "$ref": "#/definitions/learningObjectives" },
          "questions": { "$ref": "#/definitions/questions" },
          "practiceQuestions": { "$ref": "#/definitions/questions" },
          "challengeGroups": {
            "type": "array", "minItems": 2, "maxItems": 10,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["id", "title", "questionIDs"],
              "properties": {
                "id": { "$ref": "#/definitions/id" }, "title": { "$ref": "#/definitions/label" },
                "questionIDs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } }
              }
            }
          },
          "practiceGroups": {
            "type": "array", "minItems": 2, "maxItems": 10,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["id", "title", "questionIDs"],
              "properties": {
                "id": { "$ref": "#/definitions/id" }, "title": { "$ref": "#/definitions/label" },
                "questionIDs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } }
              }
            }
          },
          "previousLessonIDs": { "type": "array", "minItems": 1, "maxItems": 10, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } },
          "questionOrder": { "enum": ["declared", "shuffle"] },
          "sourceStudyItemIDs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/definitions/id" } }
        }
      }
    },
    "materials": {
      "type": "array", "maxItems": 200,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["id", "kind", "title"],
        "properties": {
          "id": { "$ref": "#/definitions/id" }, "kind": { "enum": ["passage", "image", "audio", "video"] },
          "title": { "$ref": "#/definitions/label" },
          "text": { "type": "string", "minLength": 1, "maxLength": 12000 },
          "mimeType": { "enum": ["image/png", "image/jpeg", "audio/mpeg", "audio/wav"] },
          "base64": { "type": "string", "minLength": 4, "maxLength": 2796204 },
          "asset": {"oneOf": [{"$ref": "#/definitions/asset"}, {"$ref": "#/definitions/videoAsset"}]},
          "video": {"type": "object", "additionalProperties": false, "required": ["mode"], "properties": {"mode": {"const": "linear"}, "autoplay": {"enum": ["oncePerActivity", "manual"]}}},
          "narration": {
            "type": "object", "additionalProperties": false, "required": ["practice"],
            "properties": { "practice": { "enum": ["autoOnce", "manual", "off"] } }
          },
          "transcript": {
            "type": "object", "additionalProperties": false, "required": ["text", "practice"],
            "properties": {
              "text": { "type": "string", "minLength": 1, "maxLength": 12000, "pattern": "\\S" },
              "practice": { "enum": ["always", "afterFirstAnswer", "hidden"] }
            }
          },
          "glossary": {
            "type": "array", "minItems": 1, "maxItems": 12,
            "items": {
              "type": "object", "additionalProperties": false, "required": ["term", "meaning"],
              "properties": { "term": { "$ref": "#/definitions/label" }, "meaning": { "$ref": "#/definitions/label" } }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "clientSupport": {
      "type": "object", "additionalProperties": false, "required": ["platforms"],
      "properties": {
        "registryRevision": { "type": "integer", "minimum": 1, "maximum": 1000000 },
        "platforms": {
          "type": "object", "additionalProperties": false, "minProperties": 1,
          "properties": {
            "ios": { "$ref": "#/definitions/platformSupport" },
            "android": { "$ref": "#/definitions/platformSupport" },
            "harmony": { "$ref": "#/definitions/platformSupport" }
          }
        }
      }
    },
    "platformSupport": {
      "type": "object", "additionalProperties": false, "required": ["status"],
      "properties": {
        "status": { "enum": ["supported", "unsupported"] },
        "minVersion": { "type": "string", "pattern": "^(0|[1-9][0-9]{0,3})\\.(0|[1-9][0-9]{0,3})\\.(0|[1-9][0-9]{0,3})$" }
      }
    },
    "upgrade": {
      "type": "object", "additionalProperties": false, "required": ["compatibility"],
      "properties": {
        "compatibility": { "enum": ["compatible", "incompatible"] },
        "summary": { "type": "string", "minLength": 1, "maxLength": 500, "pattern": "\\S" },
        "effects": {
          "type": "array", "maxItems": 20,
          "items": { "type": "string", "minLength": 1, "maxLength": 300, "pattern": "\\S" }
        }
      }
    },
    "learningObjectives": {
      "type": "array", "maxItems": 20,
      "items": { "type": "string", "minLength": 1, "maxLength": 300, "pattern": "\\S" }
    },
    "answerInput": {
      "type": "object", "additionalProperties": false, "required": ["profile", "preferredMode"],
      "properties": {
        "profile": { "enum": ["englishWord", "englishText", "chineseText", "freeText"] },
        "preferredMode": { "enum": ["automatic", "keyboard", "handwriting"] }
      }
    },
    "inputPolicy": { "enum": ["automatic", "unrestricted", "letters", "numbers", "full", "handwriting"] },
    "httpsURL": { "type": "string", "pattern": "^https://[^\\s]+$", "maxLength": 2000 },
    "videoAsset": {"type": "object", "additionalProperties": false, "required": ["sha256", "byteLength", "mimeType"], "properties": {"sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"}, "byteLength": {"type": "integer", "minimum": 1, "maximum": 536870912}, "mimeType": {"const": "video/mp4"}}},
    "asset": {
      "type": "object", "additionalProperties": false,
      "required": ["sha256", "byteLength", "mimeType"],
      "properties": {
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "byteLength": { "type": "integer", "minimum": 1, "maximum": 2097152 },
        "mimeType": { "enum": ["image/webp", "image/png", "image/jpeg", "audio/mpeg", "audio/wav"] }
      }
    },
    "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,79}$", "not": { "enum": ["constructor", "prototype", "__proto__"] } },
    "label": { "type": "string", "minLength": 1, "maxLength": 400 },
    "mathInteraction": {
      "oneOf": [
        {"type": "object", "additionalProperties": false, "required": ["kind"], "properties": {"kind": {"const": "number"}}},
        {"type": "object", "additionalProperties": false, "required": ["kind", "unit"], "properties": {"kind": {"const": "quantity"}, "unit": {"enum": ["cm", "m", "mm"]}}},
        {"type": "object", "additionalProperties": false, "required": ["kind"], "properties": {"kind": {"const": "expression"}}},
        {"type": "object", "additionalProperties": false, "required": ["kind", "labels"], "properties": {"kind": {"const": "blanks"}, "labels": {"type": "array", "minItems": 1, "maxItems": 8, "items": {"type": "string", "minLength": 1, "maxLength": 80}}}},
        {"type": "object", "additionalProperties": false, "required": ["kind", "shape", "parts"], "properties": {"kind": {"const": "regions"}, "shape": {"enum": ["pentagon", "rectangle", "circle"]}, "parts": {"type": "integer", "minimum": 2, "maximum": 12}}},
        {"type": "object", "additionalProperties": false, "required": ["kind", "columns"], "properties": {"kind": {"const": "table"}, "columns": {"type": "array", "minItems": 1, "maxItems": 8, "items": {"type": "string", "minLength": 1, "maxLength": 80}}}},
        {"type": "object", "additionalProperties": false, "required": ["kind", "mode"], "properties": {"kind": {"const": "angle"}, "mode": {"enum": ["draw", "measure"]}, "givenDegrees": {"type": "integer", "minimum": 1, "maximum": 179}}},
        {"type": "object", "additionalProperties": false, "required": ["kind"], "properties": {"kind": {"const": "circles"}}}
      ]
    },
    "structuredResponse": {
      "type": "object", "additionalProperties": false, "required": ["kind", "labels"],
      "properties": {
        "kind": { "enum": ["matching", "classification", "blanks", "sequence"] },
        "labels": { "$ref": "#/definitions/structuredLabels" },
        "choices": { "$ref": "#/definitions/structuredLabels" }
      }
    },
    "structuredLabels": {
      "type": "array", "minItems": 2, "maxItems": 8, "uniqueItems": true,
      "items": { "type": "string", "minLength": 1, "maxLength": 120 }
    },
    "questions": {
      "type": "array", "minItems": 1, "maxItems": 100,
      "items": {
              "type": "object", "additionalProperties": false,
              "required": ["id", "knowledgePointID", "type", "skill", "prompt", "materialIDs", "options", "answer", "explanation"],
              "properties": {
                "id": { "$ref": "#/definitions/id" },
                "knowledgePointID": { "$ref": "#/definitions/id" },
                "type": { "enum": ["singleChoice", "multipleChoice", "text", "wordOrder"] },
                "skill": { "enum": ["meaning", "spelling", "reading", "listening", "general"] },
                "inputPolicy": { "$ref": "#/definitions/inputPolicy" },
                "math": { "$ref": "#/definitions/mathInteraction" },
                "interaction": { "$ref": "#/definitions/structuredResponse" },
                "answerInput": { "$ref": "#/definitions/answerInput" },
                "prompt": { "type": "string", "minLength": 1, "maxLength": 2000 },
                "spokenText": { "type": "string", "minLength": 1, "maxLength": 2000 },
                "materialIDs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/definitions/id" } },
                "options": {
                  "type": "array", "maxItems": 16,
                  "items": {
                    "type": "object", "additionalProperties": false, "required": ["id", "text"],
                    "properties": { "id": { "$ref": "#/definitions/id" }, "text": { "$ref": "#/definitions/label" } }
                  }
                },
                "answer": {
                  "type": "object", "additionalProperties": false, "required": ["optionIDs", "acceptedTexts"],
                  "properties": {
                    "optionIDs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/definitions/id" } },
                    "acceptedTexts": { "type": "array", "uniqueItems": true, "maxItems": 20, "items": { "$ref": "#/definitions/label" } }
                  }
                },
                "explanation": { "type": "string", "minLength": 1, "maxLength": 2000 },
                "support": {
                  "type": "object", "additionalProperties": false, "required": ["promptTranslation", "hint"],
                  "properties": {
                    "promptTranslation": { "$ref": "#/definitions/label" },
                    "hint": { "$ref": "#/definitions/label" }
                  }
                },
                "evidence": {
                  "type": "array", "minItems": 1, "maxItems": 4,
                  "items": {
                    "type": "object", "additionalProperties": false, "required": ["materialID", "quote", "translation"],
                    "properties": {
                      "materialID": { "$ref": "#/definitions/id" },
                      "quote": { "type": "string", "minLength": 1, "maxLength": 2000 },
                      "translation": { "type": "string", "minLength": 1, "maxLength": 2000 }
                    }
                  }
                }
              }
      }
    }
  }
}
