{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mnstry.org/contracts/org/org-topic.v1.schema.json",
  "title": "MNSTRY.org topic v1",
  "description": "A public topic as an ordered course of published writing, with explicit cross-course junction destinations.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "contract",
    "id",
    "topic",
    "framing",
    "readingOrder",
    "completion",
    "practice",
    "graph"
  ],
  "properties": {
    "schema": { "const": "org-topic@v1" },
    "contract": { "const": "https://mnstry.org/contracts/org/org-topic.v1.schema.json" },
    "id": { "type": "string", "pattern": "^org:courses:[a-z0-9][a-z0-9.-]*$" },
    "topic": { "type": "string", "minLength": 1 },
    "framing": { "type": "string", "minLength": 1 },
    "readingOrder": {
      "type": "array",
      "minItems": 2,
      "items": { "$ref": "#/$defs/step" }
    },
    "completion": { "type": "string", "minLength": 1 },
    "practice": { "type": "string", "minLength": 1 },
    "graph": { "type": "string", "format": "uri", "pattern": "^https://" }
  },
  "$defs": {
    "writingId": {
      "type": "string",
      "pattern": "^org:writing:[a-z0-9][a-z0-9.-]*$"
    },
    "junction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["brick", "transition", "targetCourse"],
      "properties": {
        "brick": { "$ref": "#/$defs/writingId" },
        "transition": { "type": "string", "minLength": 1 },
        "targetCourse": { "type": "string", "pattern": "^org:courses:[a-z0-9][a-z0-9.-]*$" }
      }
    },
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "transition", "url", "json"],
      "properties": {
        "id": { "$ref": "#/$defs/writingId" },
        "title": { "type": "string", "minLength": 1 },
        "transition": { "type": "string", "minLength": 1 },
        "junction": { "$ref": "#/$defs/junction" },
        "url": { "type": "string", "format": "uri", "pattern": "^https://" },
        "json": { "type": "string", "format": "uri", "pattern": "^https://" }
      }
    }
  }
}
