{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "donutgram native plugin page v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "title",
    "nodes"
  ],
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "x-nativeLength": "utf16"
    },
    "nodes": {
      "type": "array",
      "maxItems": 128,
      "items": {
        "$ref": "#/$defs/node"
      }
    }
  },
  "$defs": {
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "id"
      ],
      "properties": {
        "type": {
          "enum": [
            "section",
            "text",
            "markdown",
            "list",
            "button",
            "toggle",
            "input",
            "multiline",
            "select",
            "slider",
            "stepper",
            "image"
          ]
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$"
        },
        "title": {
          "type": "string",
          "maxLength": 200,
          "x-nativeLength": "utf16"
        },
        "text": {
          "type": "string",
          "maxLength": 4096,
          "x-nativeLength": "utf16"
        },
        "value": {},
        "callbackId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$"
        },
        "children": {
          "type": "array",
          "maxItems": 128,
          "items": {
            "$ref": "#/$defs/node"
          }
        },
        "options": {
          "type": "array",
          "minItems": 1,
          "maxItems": 32,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "title",
              "value"
            ],
            "properties": {
              "title": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200,
                "x-nativeLength": "utf16"
              },
              "value": {
                "type": [
                  "string",
                  "number",
                  "boolean",
                  "null"
                ],
                "maxLength": 4096
              }
            }
          }
        },
        "minimum": {
          "type": "number",
          "minimum": -1000000000.0,
          "maximum": 1000000000.0
        },
        "maximum": {
          "type": "number",
          "minimum": -1000000000.0,
          "maximum": 1000000000.0
        },
        "step": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "asset": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[a-zA-Z0-9._-]+$"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "slider",
                  "stepper"
                ]
              }
            }
          },
          "then": {
            "required": [
              "callbackId"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "callbackId"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "toggle"
                ]
              }
            }
          },
          "then": {
            "required": [
              "value"
            ],
            "properties": {
              "value": {
                "type": "boolean"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "input",
                  "multiline"
                ]
              }
            }
          },
          "then": {
            "required": [
              "value"
            ],
            "properties": {
              "value": {
                "type": "string",
                "maxLength": 4096,
                "x-nativeLength": "utf16"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "select"
                ]
              }
            }
          },
          "then": {
            "required": [
              "options"
            ],
            "properties": {
              "value": {
                "type": [
                  "string",
                  "number",
                  "boolean",
                  "null"
                ],
                "maxLength": 4096
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "slider",
                  "stepper"
                ]
              }
            }
          },
          "then": {
            "required": [
              "value",
              "minimum",
              "maximum",
              "step"
            ],
            "properties": {
              "value": {
                "type": "number"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "image"
                ]
              }
            }
          },
          "then": {
            "required": [
              "asset"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "text",
                  "markdown",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "slider",
                  "stepper",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "children"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "slider",
                  "stepper",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "options"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "slider",
                  "stepper"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "asset"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "minimum"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "maximum"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "section",
                  "text",
                  "markdown",
                  "list",
                  "button",
                  "toggle",
                  "input",
                  "multiline",
                  "select",
                  "image"
                ]
              }
            }
          },
          "then": {
            "not": {
              "required": [
                "step"
              ]
            }
          }
        }
      ]
    }
  },
  "x-nativeConstraints": {
    "encodedJSONBytes": 65536,
    "maximumNodeDepth": 6,
    "rootNodeDepth": 0,
    "maximumTotalNodes": 128,
    "uniqueNodeIds": true,
    "noControlOrBidiDisplayText": true,
    "stringLengths": "utf16 code units; standard JSON Schema maxLength counts code points",
    "numericControl": "minimum < maximum; step <= maximum-minimum; <=1e6 steps; value in bounds and aligned within1e-6",
    "select": "value equals one typed scalar option; omitted value means null",
    "image": "opaque generation-owned installed raster handle, no URL/path"
  },
  "description": "run dgplugin validate-ui for relational, UTF16, total-node, id, depth and encoded-size constraints; native validation remains authoritative"
}
