{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$"
    },
    "version": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "summary": {
      "type": "string",
      "minLength": 3,
      "maxLength": 300
    },
    "riskNote": {
      "type": "string",
      "maxLength": 500
    },
    "input": {
      "$ref": "#/$defs/__schema0"
    },
    "effects": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "money.out",
          "money.in",
          "message.sent",
          "data.read",
          "data.write",
          "data.delete",
          "permission.change",
          "approval.grant",
          "physical.motion",
          "physical.grip"
        ]
      }
    },
    "reversibility": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "undoable"
            },
            "via": {
              "type": "string"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "compensable"
            },
            "via": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "kind",
            "via"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "irreversible"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        }
      ]
    },
    "blastRadius": {
      "type": "object",
      "properties": {
        "scope": {
          "type": "string",
          "enum": [
            "none",
            "self",
            "customer",
            "workspace",
            "physical"
          ]
        },
        "scopeField": {
          "type": "string"
        },
        "amountField": {
          "type": "string"
        },
        "maxAmount": {
          "type": "number",
          "minimum": 0
        },
        "perWindow": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            },
            "windowSeconds": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            }
          },
          "required": [
            "count",
            "windowSeconds"
          ],
          "additionalProperties": false
        },
        "recipientsField": {
          "type": "string"
        },
        "maxRecipients": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        },
        "safeZone": {
          "type": "object",
          "properties": {
            "min": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "number"
                },
                {
                  "type": "number"
                },
                {
                  "type": "number"
                }
              ],
              "items": false,
              "minItems": 3,
              "maxItems": 3
            },
            "max": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "number"
                },
                {
                  "type": "number"
                },
                {
                  "type": "number"
                }
              ],
              "items": false,
              "minItems": 3,
              "maxItems": 3
            }
          },
          "required": [
            "min",
            "max"
          ],
          "additionalProperties": false
        },
        "targetField": {
          "type": "string"
        },
        "speedField": {
          "type": "string"
        },
        "maxSpeed": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "scope"
      ],
      "additionalProperties": false
    },
    "preconditions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "idempotency": {
      "type": "object",
      "properties": {
        "key": {
          "minItems": 1,
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "windowSeconds": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "key",
        "windowSeconds"
      ],
      "additionalProperties": false
    },
    "approval": {
      "type": "object",
      "properties": {
        "when": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "when"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "id",
    "version",
    "summary",
    "input",
    "effects",
    "reversibility",
    "blastRadius",
    "preconditions"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "object",
            "string",
            "number",
            "integer",
            "boolean",
            "array"
          ]
        },
        "properties": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        },
        "required": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "enum": {
          "type": "array",
          "items": {
            "type": [
              "string",
              "number"
            ]
          }
        },
        "minimum": {
          "type": "number"
        },
        "maximum": {
          "type": "number"
        },
        "exclusiveMinimum": {
          "type": "number"
        },
        "minLength": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "maxLength": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "items": {
          "$ref": "#/$defs/__schema0"
        },
        "description": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    }
  }
}
