{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Macro Handler block package (editor assistance)",
  "description": "Run the SDK CLI and Android importer too. Byte limits, duplicate keys, UTF16 lengths, cross-field/default semantics and Lua compilation need those checks. Do not add $schema to the package.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "macrohandler.block"
    },
    "schemaVersion": {
      "enum": [
        1,
        2,
        3
      ]
    },
    "id": {
      "type": "string",
      "maxLength": 96,
      "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$"
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]{1,5}\\.[0-9]{1,5}\\.[0-9]{1,5}(?:-[a-zA-Z0-9.-]{1,32})?$"
    },
    "name": {
      "type": "string",
      "maxLength": 80,
      "minLength": 1
    },
    "description": {
      "type": "string",
      "maxLength": 2048
    },
    "author": {
      "type": "string",
      "maxLength": 120
    },
    "inputs": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/input"
      },
      "maxItems": 24
    },
    "code": {
      "type": "string",
      "maxLength": 131072
    },
    "native": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "entry": {
              "enum": [
                "navigation",
                "navigation_stop",
                "agent_detect",
                "agent_routine"
              ]
            },
            "apiVersion": {
              "const": 1
            },
            "source": {
              "type": "string",
              "maxLength": 512,
              "minLength": 1
            }
          },
          "required": [
            "entry",
            "apiVersion",
            "source"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "form": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "layout": {
              "enum": [
                "stack",
                "sections"
              ],
              "default": "stack"
            },
            "groups": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "pattern": "^[A-Za-z][A-Za-z0-9_]{0,47}$"
                  },
                  "label": {
                    "type": "string",
                    "maxLength": 80,
                    "minLength": 1
                  },
                  "help": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 1024
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "id",
                  "label"
                ]
              },
              "maxItems": 8
            }
          },
          "required": []
        },
        {
          "type": "null"
        }
      ]
    },
    "presentation": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "category": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 80,
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "icon": {
              "anyOf": [
                {
                  "enum": [
                    "block",
                    "code",
                    "search",
                    "touch",
                    "flow",
                    "data"
                  ]
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": []
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "format",
    "schemaVersion",
    "id",
    "version",
    "name",
    "code"
  ],
  "definitions": {
    "input": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-zA-Z_][a-zA-Z0-9_]{0,47}$"
        },
        "label": {
          "type": "string",
          "maxLength": 80,
          "minLength": 1
        },
        "type": {
          "enum": [
            "text",
            "number",
            "boolean",
            "choice",
            "color",
            "variable",
            "point",
            "region"
          ],
          "default": "text"
        },
        "defaultValue": {
          "type": "string",
          "maxLength": 8192,
          "default": ""
        },
        "choices": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 256
          },
          "maxItems": 64,
          "uniqueItems": true,
          "default": []
        },
        "help": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 1024
            },
            {
              "type": "null"
            }
          ]
        },
        "unit": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 24
            },
            {
              "type": "null"
            }
          ]
        },
        "group": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 48
            },
            {
              "type": "null"
            }
          ]
        },
        "advanced": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "multiline": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "required": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "min": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "max": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        },
        "step": {
          "anyOf": [
            {
              "type": "number",
              "exclusiveMinimum": 0
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "key",
        "label"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "choice"
              }
            },
            "required": [
              "type"
            ]
          },
          "then": {
            "required": [
              "choices"
            ],
            "properties": {
              "choices": {
                "minItems": 1
              }
            }
          },
          "else": {
            "properties": {
              "choices": {
                "maxItems": 0
              }
            }
          }
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "schemaVersion": {
            "const": 2
          }
        }
      },
      "then": {
        "required": [
          "native"
        ],
        "properties": {
          "native": {
            "type": "object"
          },
          "code": {
            "const": ""
          },
          "inputs": {
            "maxItems": 0
          }
        }
      },
      "else": {
        "properties": {
          "native": {
            "type": "null"
          },
          "code": {
            "minLength": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "schemaVersion": {
            "enum": [
              1,
              2
            ]
          }
        }
      },
      "then": {
        "properties": {
          "form": {
            "type": "null"
          },
          "presentation": {
            "type": "null"
          },
          "inputs": {
            "items": {
              "properties": {
                "type": {
                  "enum": [
                    "text",
                    "number",
                    "boolean",
                    "choice"
                  ]
                },
                "help": {
                  "type": "null"
                },
                "unit": {
                  "type": "null"
                },
                "group": {
                  "type": "null"
                },
                "advanced": {
                  "type": "null"
                },
                "multiline": {
                  "type": "null"
                },
                "required": {
                  "type": "null"
                },
                "min": {
                  "type": "null"
                },
                "max": {
                  "type": "null"
                },
                "step": {
                  "type": "null"
                }
              }
            }
          }
        }
      }
    }
  ]
}
