{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://miragon.github.io/bpmn-to-code/schema/process-model/2.0.json",
    "title": "bpmn-to-code process model",
    "description": "Structured, BPMN-standard-aligned representation of a BPMN process, generated by bpmn-to-code. See https://miragon.github.io/bpmn-to-code/surface/json.",
    "type": "object",
    "required": ["process"],
    "properties": {
        "$schema": { "type": "string", "format": "uri" },
        "formatVersion": { "type": "string", "enum": ["2.0", "2.1"] },
        "process": { "$ref": "#/$defs/process" },
        "definitions": { "$ref": "#/$defs/definitions" },
        "variants": {
            "type": "array",
            "description": "Per-variant subsets of a merged model, emitted up to 6.1. No longer generated: every BPMN file gets a JSON of its own.",
            "items": { "$ref": "#/$defs/variant" }
        }
    },
    "additionalProperties": false,
    "$defs": {
        "process": {
            "type": "object",
            "required": ["id"],
            "properties": {
                "id": { "type": "string" },
                "name": { "type": "string" },
                "isExecutable": { "type": "boolean", "default": true },
                "engine": { "enum": ["ZEEBE", "CAMUNDA_7", "OPERATON"] },
                "flowNodes": { "type": "array", "items": { "$ref": "#/$defs/flowNode" } },
                "sequenceFlows": { "type": "array", "items": { "$ref": "#/$defs/sequenceFlow" } }
            },
            "additionalProperties": false
        },
        "variant": {
            "type": "object",
            "required": ["name"],
            "properties": {
                "name": { "type": "string" },
                "flowNodes": { "type": "array", "items": { "$ref": "#/$defs/flowNode" } },
                "sequenceFlows": { "type": "array", "items": { "$ref": "#/$defs/sequenceFlow" } }
            },
            "additionalProperties": false
        },
        "definitions": {
            "type": "object",
            "description": "bpmn:Definitions root elements, de-duplicated by their own id and referenced from event definitions.",
            "properties": {
                "messages": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["id", "name"],
                        "properties": {
                            "id": { "type": "string" },
                            "name": { "type": "string" },
                            "correlationKey": {
                                "type": "string",
                                "description": "Zeebe zeebe:subscription expression, declared on the message element itself."
                            }
                        },
                        "additionalProperties": false
                    }
                },
                "signals": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["id", "name"],
                        "properties": {
                            "id": { "type": "string" },
                            "name": { "type": "string" }
                        },
                        "additionalProperties": false
                    }
                },
                "errors": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["id", "name"],
                        "properties": {
                            "id": { "type": "string" },
                            "name": { "type": "string" },
                            "errorCode": { "type": "string" }
                        },
                        "additionalProperties": false
                    }
                },
                "escalations": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["id", "name"],
                        "properties": {
                            "id": { "type": "string" },
                            "name": { "type": "string" },
                            "escalationCode": { "type": "string" }
                        },
                        "additionalProperties": false
                    }
                }
            },
            "additionalProperties": false
        },
        "flowNode": {
            "type": "object",
            "required": ["id", "type"],
            "properties": {
                "id": { "type": "string" },
                "type": {
                    "description": "The BPMN element name. Prefix with 'bpmn:' to get the bpmn-moddle $type.",
                    "enum": [
                        "task",
                        "serviceTask",
                        "userTask",
                        "receiveTask",
                        "sendTask",
                        "scriptTask",
                        "manualTask",
                        "businessRuleTask",
                        "subProcess",
                        "transaction",
                        "callActivity",
                        "exclusiveGateway",
                        "parallelGateway",
                        "inclusiveGateway",
                        "eventBasedGateway",
                        "complexGateway",
                        "startEvent",
                        "endEvent",
                        "intermediateCatchEvent",
                        "intermediateThrowEvent",
                        "boundaryEvent",
                        "unknown"
                    ]
                },
                "name": { "type": "string" },
                "incoming": {
                    "type": "array",
                    "description": "Ids of incoming sequence flows (not of the preceding nodes).",
                    "items": { "type": "string" }
                },
                "outgoing": {
                    "type": "array",
                    "description": "Ids of outgoing sequence flows (not of the following nodes).",
                    "items": { "type": "string" }
                },
                "default": { "type": "string", "description": "Id of the default sequence flow." },
                "attachedToRef": { "type": "string", "description": "Host activity of a boundary event." },
                "compensationHandlerRef": { "type": "string", "description": "Compensation boundary events: the compensation handler the event is associated with. Since 2.1." },
                "cancelActivity": { "type": "boolean", "description": "Boundary events: whether the event interrupts its host." },
                "isInterrupting": { "type": "boolean", "description": "Event sub-process start events: whether the event interrupts its scope." },
                "triggeredByEvent": { "type": "boolean", "description": "Marks a sub-process as an event sub-process." },
                "isForCompensation": { "type": "boolean" },
                "boundaryEventRefs": { "type": "array", "items": { "type": "string" } },
                "eventDefinitions": { "type": "array", "items": { "$ref": "#/$defs/eventDefinition" } },
                "messageRef": { "type": "string", "description": "Send/receive tasks reference their message directly." },
                "implementation": { "$ref": "#/$defs/implementation" },
                "calledElement": { "$ref": "#/$defs/calledElement" },
                "multiInstance": { "$ref": "#/$defs/multiInstance" },
                "ioMapping": { "$ref": "#/$defs/ioMapping" },
                "flowNodes": {
                    "type": "array",
                    "description": "Children of a sub-process scope.",
                    "items": { "$ref": "#/$defs/flowNode" }
                },
                "sequenceFlows": {
                    "type": "array",
                    "description": "Sequence flows owned by a sub-process scope.",
                    "items": { "$ref": "#/$defs/sequenceFlow" }
                },
                "extensions": { "type": "array", "items": { "$ref": "#/$defs/extension" } },
                "engineAttributes": {
                    "type": "object",
                    "description": "Foreign-namespace attributes, keyed as prefix:localName.",
                    "additionalProperties": true
                }
            },
            "additionalProperties": false
        },
        "sequenceFlow": {
            "type": "object",
            "required": ["id", "sourceRef", "targetRef"],
            "properties": {
                "id": { "type": "string" },
                "sourceRef": { "type": "string" },
                "targetRef": { "type": "string" },
                "name": { "type": "string" },
                "conditionExpression": { "type": "string" },
                "isDefault": { "type": "boolean", "description": "True if this is the source's default flow." }
            },
            "additionalProperties": false
        },
        "eventDefinition": {
            "type": "object",
            "required": ["type"],
            "properties": {
                "type": {
                    "enum": [
                        "timer",
                        "message",
                        "signal",
                        "error",
                        "escalation",
                        "compensation",
                        "conditional",
                        "link",
                        "terminate"
                    ]
                },
                "timerType": { "enum": ["DATE", "DURATION", "CYCLE"] },
                "expression": { "type": "string" },
                "messageRef": { "type": "string" },
                "signalRef": { "type": "string" },
                "errorRef": { "type": "string" },
                "escalationRef": { "type": "string" },
                "activityRef": { "type": "string" },
                "waitForCompletion": { "type": "boolean" },
                "linkName": { "type": "string" }
            },
            "additionalProperties": false
        },
        "implementation": {
            "type": "object",
            "required": ["type"],
            "properties": {
                "type": {
                    "enum": [
                        "jobWorker",
                        "connector",
                        "externalTask",
                        "javaClass",
                        "delegateExpression",
                        "expression"
                    ]
                },
                "jobType": { "type": "string" },
                "templateId": { "type": "string" },
                "retries": { "type": "string" },
                "topic": { "type": "string" },
                "className": { "type": "string" },
                "expression": { "type": "string" }
            },
            "additionalProperties": false
        },
        "calledElement": {
            "type": "object",
            "properties": {
                "processId": { "type": "string" },
                "propagateAllInputVariables": { "type": "boolean" },
                "propagateAllOutputVariables": { "type": "boolean" }
            },
            "additionalProperties": false
        },
        "multiInstance": {
            "type": "object",
            "required": ["sequential"],
            "properties": {
                "sequential": { "type": "boolean" },
                "inputCollection": { "type": "string" },
                "inputElement": { "type": "string" },
                "outputCollection": { "type": "string" },
                "outputElement": { "type": "string" },
                "cardinality": { "type": "string" },
                "completionCondition": { "type": "string" }
            },
            "additionalProperties": false
        },
        "ioMapping": {
            "type": "object",
            "properties": {
                "inputs": { "type": "array", "items": { "$ref": "#/$defs/ioParameter" } },
                "outputs": { "type": "array", "items": { "$ref": "#/$defs/ioParameter" } }
            },
            "additionalProperties": false
        },
        "ioParameter": {
            "type": "object",
            "required": ["target"],
            "properties": {
                "target": { "type": "string" },
                "source": { "type": "string" }
            },
            "additionalProperties": false
        },
        "extension": {
            "type": "object",
            "description": "Verbatim projection of a foreign-namespace element below bpmn:extensionElements.",
            "required": ["$type"],
            "properties": {
                "$type": { "type": "string", "description": "prefix:localName, e.g. zeebe:taskHeaders" },
                "attributes": { "type": "object", "additionalProperties": { "type": "string" } },
                "children": { "type": "array", "items": { "$ref": "#/$defs/extension" } },
                "body": { "type": "string" }
            },
            "additionalProperties": false
        }
    }
}
