{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-journey-version-schema.json",
  "title": "JourneyVersion",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-journeys-api-openapi.yml#/components/schemas/JourneyVersion",
  "type": "object",
  "properties": {
    "journeyId": {
      "$ref": "#/$defs/JourneyId"
    },
    "version": {
      "type": "integer",
      "minimum": -9007199254740991,
      "maximum": 9007199254740991
    },
    "definition": {
      "$ref": "#/$defs/JourneyDefinition"
    },
    "publishedAt": {
      "type": "string"
    }
  },
  "required": [
    "journeyId",
    "version",
    "definition",
    "publishedAt"
  ],
  "additionalProperties": false,
  "$defs": {
    "ContactGroupId": {
      "type": "string",
      "pattern": "^cgrp_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactGroupId"
    },
    "EmailSenderId": {
      "type": "string",
      "pattern": "^sender_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "EmailSenderId"
    },
    "JourneyBranchEdge": {
      "type": "object",
      "properties": {
        "nodeId": {
          "$ref": "#/$defs/JourneyNodeId"
        },
        "condition": {
          "$ref": "#/$defs/JourneyCondition"
        }
      },
      "required": [
        "nodeId"
      ],
      "additionalProperties": false
    },
    "JourneyBranchNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "branch"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyEmptyConfig"
        },
        "next": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JourneyBranchEdge"
          },
          "minItems": 2
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyComparison": {
      "anyOf": [
        {
          "$ref": "#/$defs/JourneyEqualityComparison"
        },
        {
          "$ref": "#/$defs/JourneyNumericComparison"
        },
        {
          "$ref": "#/$defs/JourneyStringComparison"
        },
        {
          "$ref": "#/$defs/JourneyPresenceComparison"
        }
      ]
    },
    "JourneyCondition": {
      "type": "object",
      "properties": {
        "match": {
          "type": "string",
          "enum": [
            "all",
            "any"
          ]
        },
        "predicates": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyPredicate"
            }
          ],
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/JourneyPredicate"
          }
        }
      },
      "required": [
        "match",
        "predicates"
      ],
      "additionalProperties": false
    },
    "JourneyContactCreatedTrigger": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "contact.created"
          ]
        }
      },
      "required": [
        "type"
      ],
      "additionalProperties": false
    },
    "JourneyContactProperty": {
      "type": "string",
      "enum": [
        "name",
        "displayName",
        "externalId",
        "status",
        "profile.firstName",
        "profile.lastName",
        "profile.company",
        "profile.jobTitle",
        "profile.source",
        "profile.location.country",
        "profile.location.state",
        "profile.location.city",
        "profile.location.timezone"
      ]
    },
    "JourneyCustomEventName": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "x-samva-string-checks": [
        {
          "id": "effect/schema/isMaxLength",
          "payload": {
            "maxLength": 255
          }
        },
        {
          "id": "effect/schema/isPattern",
          "payload": {
            "source": "^(?!(?:[Cc][Oo][Nn][Tt][Aa][Cc][Tt]|[Ss][Aa][Mm][Vv][Aa])\\.)[A-Za-z][A-Za-z0-9_.-]*$",
            "flags": ""
          }
        }
      ]
    },
    "JourneyCustomEventTrigger": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "event"
          ]
        },
        "eventName": {
          "$ref": "#/$defs/JourneyCustomEventName"
        }
      },
      "required": [
        "type",
        "eventName"
      ],
      "additionalProperties": false
    },
    "JourneyCustomFieldPredicate": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "custom_field"
          ]
        },
        "key": {
          "type": "string",
          "minLength": 1
        },
        "comparison": {
          "$ref": "#/$defs/JourneyComparison"
        }
      },
      "required": [
        "type",
        "key",
        "comparison"
      ],
      "additionalProperties": false
    },
    "JourneyDefinition": {
      "type": "object",
      "properties": {
        "trigger": {
          "$ref": "#/$defs/JourneyTrigger"
        },
        "rootNodeId": {
          "$ref": "#/$defs/JourneyNodeId"
        },
        "nodes": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JourneyNode"
          },
          "minProperties": 1,
          "maxProperties": 200
        },
        "goal": {
          "$ref": "#/$defs/JourneyGoal"
        },
        "reentry": {
          "type": "boolean"
        }
      },
      "required": [
        "trigger",
        "rootNodeId",
        "nodes"
      ],
      "additionalProperties": false
    },
    "JourneyEmptyConfig": {
      "type": "object",
      "additionalProperties": false
    },
    "JourneyEqualityComparison": {
      "type": "object",
      "properties": {
        "operator": {
          "type": "string",
          "enum": [
            "eq",
            "neq"
          ]
        },
        "value": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "operator",
        "value"
      ],
      "additionalProperties": false
    },
    "JourneyEventName": {
      "anyOf": [
        {
          "$ref": "#/$defs/JourneyCustomEventName"
        },
        {
          "type": "string",
          "enum": [
            "contact.created",
            "contact.tag_added",
            "contact.joined_group"
          ]
        }
      ]
    },
    "JourneyEventPredicate": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "event"
          ]
        },
        "eventName": {
          "$ref": "#/$defs/JourneyEventName"
        },
        "occurred": {
          "type": "boolean"
        }
      },
      "required": [
        "type",
        "eventName",
        "occurred"
      ],
      "additionalProperties": false
    },
    "JourneyExitNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "exit"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyEmptyConfig"
        },
        "next": {
          "type": "array",
          "items": false
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyGoal": {
      "type": "object",
      "properties": {
        "eventName": {
          "$ref": "#/$defs/JourneyEventName"
        }
      },
      "required": [
        "eventName"
      ],
      "additionalProperties": false
    },
    "JourneyGroupJoinedTrigger": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "contact.joined_group"
          ]
        },
        "groupId": {
          "$ref": "#/$defs/ContactGroupId"
        }
      },
      "required": [
        "type",
        "groupId"
      ],
      "additionalProperties": false
    },
    "JourneyId": {
      "type": "string",
      "pattern": "^jrny_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "JourneyId"
    },
    "JourneyNextEdge": {
      "type": "object",
      "properties": {
        "nodeId": {
          "$ref": "#/$defs/JourneyNodeId"
        }
      },
      "required": [
        "nodeId"
      ],
      "additionalProperties": false
    },
    "JourneyNode": {
      "anyOf": [
        {
          "$ref": "#/$defs/JourneySendEmailNode"
        },
        {
          "$ref": "#/$defs/JourneyWaitNode"
        },
        {
          "$ref": "#/$defs/JourneyWaitForEventNode"
        },
        {
          "$ref": "#/$defs/JourneyBranchNode"
        },
        {
          "$ref": "#/$defs/JourneyUpdateTagsNode"
        },
        {
          "$ref": "#/$defs/JourneyWebhookNode"
        },
        {
          "$ref": "#/$defs/JourneyExitNode"
        }
      ]
    },
    "JourneyNodeId": {
      "type": "string",
      "minLength": 1
    },
    "JourneyNumericComparison": {
      "type": "object",
      "properties": {
        "operator": {
          "type": "string",
          "enum": [
            "gt",
            "gte",
            "lt",
            "lte"
          ]
        },
        "value": {
          "type": "number"
        }
      },
      "required": [
        "operator",
        "value"
      ],
      "additionalProperties": false
    },
    "JourneyPredicate": {
      "anyOf": [
        {
          "$ref": "#/$defs/JourneyTagPredicate"
        },
        {
          "$ref": "#/$defs/JourneyPropertyPredicate"
        },
        {
          "$ref": "#/$defs/JourneyCustomFieldPredicate"
        },
        {
          "$ref": "#/$defs/JourneyEventPredicate"
        }
      ]
    },
    "JourneyPresenceComparison": {
      "type": "object",
      "properties": {
        "operator": {
          "type": "string",
          "enum": [
            "exists",
            "not_exists"
          ]
        }
      },
      "required": [
        "operator"
      ],
      "additionalProperties": false
    },
    "JourneyPropertyPredicate": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "property"
          ]
        },
        "field": {
          "$ref": "#/$defs/JourneyContactProperty"
        },
        "comparison": {
          "$ref": "#/$defs/JourneyComparison"
        }
      },
      "required": [
        "type",
        "field",
        "comparison"
      ],
      "additionalProperties": false
    },
    "JourneySendEmailConfig": {
      "type": "object",
      "properties": {
        "template": {
          "anyOf": [
            {
              "$ref": "#/$defs/TemplateId"
            },
            {
              "type": "string",
              "pattern": "^(?=.{1,100}$)[a-z0-9]+(?:-[a-z0-9]+)*$"
            }
          ]
        },
        "senderId": {
          "$ref": "#/$defs/EmailSenderId"
        },
        "templateData": {
          "$ref": "#/$defs/JsonObject"
        }
      },
      "required": [
        "template"
      ],
      "additionalProperties": false
    },
    "JourneySendEmailNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "send_email"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneySendEmailConfig"
        },
        "next": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyNextEdge"
            }
          ],
          "maxItems": 1,
          "minItems": 1
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyStringComparison": {
      "type": "object",
      "properties": {
        "operator": {
          "type": "string",
          "enum": [
            "contains",
            "not_contains",
            "starts_with",
            "ends_with"
          ]
        },
        "value": {
          "type": "string"
        }
      },
      "required": [
        "operator",
        "value"
      ],
      "additionalProperties": false
    },
    "JourneyTagAddedTrigger": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "contact.tag_added"
          ]
        },
        "tag": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "type",
        "tag"
      ],
      "additionalProperties": false
    },
    "JourneyTagPredicate": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "tag"
          ]
        },
        "tag": {
          "type": "string",
          "minLength": 1
        },
        "present": {
          "type": "boolean"
        }
      },
      "required": [
        "type",
        "tag",
        "present"
      ],
      "additionalProperties": false
    },
    "JourneyTrigger": {
      "anyOf": [
        {
          "$ref": "#/$defs/JourneyCustomEventTrigger"
        },
        {
          "$ref": "#/$defs/JourneyContactCreatedTrigger"
        },
        {
          "$ref": "#/$defs/JourneyTagAddedTrigger"
        },
        {
          "$ref": "#/$defs/JourneyGroupJoinedTrigger"
        }
      ]
    },
    "JourneyUpdateTagsConfig": {
      "type": "object",
      "properties": {
        "add": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "remove": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "add",
        "remove"
      ],
      "additionalProperties": false
    },
    "JourneyUpdateTagsNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "update_tags"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyUpdateTagsConfig"
        },
        "next": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyNextEdge"
            }
          ],
          "maxItems": 1,
          "minItems": 1
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyWaitConfig": {
      "type": "object",
      "properties": {
        "durationSeconds": {
          "type": "integer",
          "maximum": 7776000,
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "durationSeconds"
      ],
      "additionalProperties": false
    },
    "JourneyWaitEventEdge": {
      "type": "object",
      "properties": {
        "nodeId": {
          "$ref": "#/$defs/JourneyNodeId"
        },
        "outcome": {
          "type": "string",
          "enum": [
            "matched",
            "timed_out"
          ]
        }
      },
      "required": [
        "nodeId",
        "outcome"
      ],
      "additionalProperties": false
    },
    "JourneyWaitForEventConfig": {
      "type": "object",
      "properties": {
        "eventName": {
          "$ref": "#/$defs/JourneyEventName"
        },
        "timeoutSeconds": {
          "type": "integer",
          "maximum": 7776000,
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "eventName",
        "timeoutSeconds"
      ],
      "additionalProperties": false
    },
    "JourneyWaitForEventNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "wait_for_event"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyWaitForEventConfig"
        },
        "next": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyWaitEventEdge"
            },
            {
              "$ref": "#/$defs/JourneyWaitEventEdge"
            }
          ],
          "maxItems": 2,
          "minItems": 2
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyWaitNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "wait"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyWaitConfig"
        },
        "next": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyNextEdge"
            }
          ],
          "maxItems": 1,
          "minItems": 1
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JourneyWebhookConfig": {
      "type": "object",
      "properties": {
        "data": {
          "$ref": "#/$defs/JsonObject"
        }
      },
      "additionalProperties": false
    },
    "JourneyWebhookNode": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "webhook"
          ]
        },
        "config": {
          "$ref": "#/$defs/JourneyWebhookConfig"
        },
        "next": {
          "type": "array",
          "prefixItems": [
            {
              "$ref": "#/$defs/JourneyNextEdge"
            }
          ],
          "maxItems": 1,
          "minItems": 1
        }
      },
      "required": [
        "type",
        "config",
        "next"
      ],
      "additionalProperties": false
    },
    "JsonObject": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/JsonValue"
      }
    },
    "JsonValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "TemplateId": {
      "type": "string",
      "pattern": "^tmpl_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplateId"
    }
  }
}