{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://usebode.com/bode.schema.json",
  "title": "bode",
  "description": "A bode document, version 1.",
  "type": "object",
  "required": [
    "kind",
    "version",
    "blocks",
    "edges"
  ],
  "additionalProperties": true,
  "properties": {
    "kind": {
      "const": "bode"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "name": {
      "type": "string"
    },
    "icon": {
      "type": "string"
    },
    "blocks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/block"
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/edge"
      }
    }
  },
  "$defs": {
    "block": {
      "type": "object",
      "required": [
        "id",
        "blockId"
      ],
      "additionalProperties": true,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Unique within the document. Edges refer to it."
        },
        "blockId": {
          "type": "string",
          "description": "Which block this is, from the manifest — `text`, `jwt-decode`, `timer`."
        },
        "params": {
          "type": "object",
          "description": "The block's settings. Merged over its defaults on load, so a file may carry only what differs. Session-only params are stripped on the way out (§33), which is why a shared bode asks for YOUR clock rather than mine."
        },
        "pos": {
          "type": "object",
          "properties": {
            "x": {
              "type": "number"
            },
            "y": {
              "type": "number"
            }
          },
          "required": [
            "x",
            "y"
          ]
        },
        "size": {
          "type": "object",
          "properties": {
            "w": {
              "type": "number"
            },
            "h": {
              "type": "number"
            }
          },
          "required": [
            "w"
          ]
        },
        "notes": {
          "type": "string",
          "description": "A Markdown note about this block. Not an input."
        }
      }
    },
    "port": {
      "type": "object",
      "required": [
        "block",
        "port"
      ],
      "additionalProperties": false,
      "properties": {
        "block": {
          "type": "string"
        },
        "port": {
          "type": "string"
        }
      }
    },
    "edge": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "additionalProperties": true,
      "properties": {
        "id": {
          "type": "string"
        },
        "from": {
          "$ref": "#/$defs/port"
        },
        "to": {
          "$ref": "#/$defs/port"
        }
      }
    }
  }
}
