{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "beat-script/1",
  "title": "Beat player script",
  "description": "One walkthrough for the ONE beat player (docs/posts/using-analyst-server/player/index.html?script=<topic>). The player reads this file and nothing else: its stops, its screens and its vocabulary. A build walkthrough walks the six stops (s1..s6) on a real worked initiative; a reference tour steps screen by screen with no build loop. Routes come from the route map (web-apps/as-web/src/lib/route-map.mjs) by route_id. Checked by ops/posts/walkthrough-scripts.mjs.",
  "type": "object",
  "required": ["schema", "topic", "title", "kind", "summary", "beatMs", "stops", "screens", "vocab"],
  "additionalProperties": false,
  "properties": {
    "schema": { "const": "beat-script/1" },
    "topic": { "type": "string", "pattern": "^[a-z0-9-]+$", "description": "the file name without .json" },
    "title": { "type": "string", "minLength": 3 },
    "kind": { "enum": ["build", "tour"] },
    "summary": { "type": "string", "minLength": 10 },
    "initiative": { "type": "string", "pattern": "^[a-z0-9-]+$", "description": "build only: the real map node the walkthrough works through" },
    "beatMs": { "type": "integer", "minimum": 1500, "maximum": 15000 },
    "stops": { "type": "array", "minItems": 2, "items": { "$ref": "#/$defs/stop" } },
    "screens": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/screen" } },
    "vocab": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/card" } }
  },
  "$defs": {
    "hue": { "enum": ["conv", "page", "tree", "stream", "story"] },
    "stop": {
      "type": "object",
      "required": ["id", "glyph", "verb", "step", "screen", "on", "route_id", "route", "hue", "scr", "beats"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
        "glyph": { "type": "string", "minLength": 1, "maxLength": 3 },
        "verb": { "type": "string", "minLength": 2, "maxLength": 9 },
        "step": { "type": "string", "minLength": 2 },
        "screen": { "type": "string", "minLength": 2, "description": "proper name of the screen; must be a vocab card name" },
        "on": { "type": "string" },
        "route_id": { "type": "string", "description": "a ROUTES id in route-map.mjs" },
        "route": { "type": "string", "description": "the address shown; must match the route map row named by route_id" },
        "hue": { "$ref": "#/$defs/hue" },
        "scr": { "type": "string", "description": "a key of screens" },
        "beats": { "type": "array", "minItems": 2, "items": { "$ref": "#/$defs/beat" } }
      }
    },
    "beat": {
      "type": "object",
      "required": ["region", "tip", "line"],
      "additionalProperties": false,
      "properties": {
        "region": { "type": "string", "minLength": 1, "description": "space-separated data-r ids on the screen; 'frame' is a switch beat" },
        "tip": { "type": "string", "minLength": 1 },
        "line": { "type": "string", "minLength": 5 },
        "info": { "type": "array", "items": { "type": "string" } },
        "vocab": { "type": "string", "description": "a key of vocab; required on a switch beat" },
        "state": { "type": "string" },
        "scr": { "type": "string" },
        "screen": { "type": "string" },
        "on": { "type": "string" },
        "route_id": { "type": "string" },
        "route": { "type": "string" }
      }
    },
    "screen": {
      "type": "object",
      "required": ["kind", "hue", "crumb", "label", "rows"],
      "additionalProperties": false,
      "properties": {
        "kind": { "enum": ["chat", "page", "tree"] },
        "hue": { "$ref": "#/$defs/hue" },
        "crumb": { "type": "string" },
        "label": { "type": "string" },
        "labelByState": { "type": "object", "additionalProperties": { "type": "string" } },
        "title": { "type": "string" },
        "meta": { "type": "string" },
        "rows": {
          "type": "array", "minItems": 1,
          "items": {
            "type": "object", "required": ["html"], "additionalProperties": false,
            "properties": {
              "r": { "type": "string" },
              "html": { "type": "string" },
              "who": { "enum": ["you", "session"] },
              "show": { "type": "string" },
              "cls": { "type": "string" }
            }
          }
        }
      }
    },
    "card": {
      "type": "object",
      "required": ["name", "what", "where", "route"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string" },
        "what": { "type": "string" },
        "where": { "type": "string" },
        "route": { "type": "string" },
        "route_id": { "type": "string" }
      }
    }
  }
}
