{
  "$id": "urn:smart-mail:schemas:segment-rules:v1",
  "title": "SegmentRules",
  "description": "Árvore de regras de segmentação (v1): segmentos, exclusões de campanha e condições de automação. Nomes em camelCase, operadores em snake_case (ADR-034). Gerado de packages/contracts/src/segments.ts — não editar à mão. Limite que este schema não expressa: no máximo 10 níveis de grupos. Ver docs/segment-rules.md.",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "#/$defs/Group",
  "$defs": {
    "Group": {
      "type": "object",
      "properties": {
        "version": {
          "type": "number",
          "const": 1
        },
        "id": {
          "$ref": "#/$defs/NodeId"
        },
        "negate": {
          "type": "boolean"
        },
        "operator": {
          "type": "string",
          "enum": [
            "AND",
            "OR"
          ]
        },
        "conditions": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/Node"
          }
        }
      },
      "required": [
        "operator",
        "conditions"
      ],
      "additionalProperties": false
    },
    "NodeId": {
      "type": "string",
      "maxLength": 64
    },
    "Node": {
      "anyOf": [
        {
          "$ref": "#/$defs/Group"
        },
        {
          "$ref": "#/$defs/Condition"
        }
      ]
    },
    "Condition": {
      "oneOf": [
        {
          "$ref": "#/$defs/AttributeCondition"
        },
        {
          "$ref": "#/$defs/ListCondition"
        },
        {
          "$ref": "#/$defs/TagCondition"
        },
        {
          "$ref": "#/$defs/SegmentCondition"
        },
        {
          "$ref": "#/$defs/EngagementCondition"
        },
        {
          "$ref": "#/$defs/EventCondition"
        },
        {
          "$ref": "#/$defs/EcommerceCondition"
        },
        {
          "$ref": "#/$defs/AutomationCondition"
        },
        {
          "$ref": "#/$defs/SourceCondition"
        }
      ]
    },
    "AttributeCondition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "is_empty",
                "is_not_empty"
              ]
            }
          },
          "required": [
            "type",
            "field",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "equals",
                "not_equals",
                "contains",
                "not_contains",
                "starts_with",
                "ends_with",
                "gt",
                "gte",
                "lt",
                "lte",
                "before",
                "after",
                "on"
              ]
            },
            "value": {
              "$ref": "#/$defs/Scalar"
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "const": "between"
            },
            "value": {
              "type": "array",
              "prefixItems": [
                {
                  "type": [
                    "number",
                    "string"
                  ]
                },
                {
                  "type": [
                    "number",
                    "string"
                  ]
                }
              ],
              "items": false,
              "minItems": 2,
              "maxItems": 2
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "in",
                "not_in",
                "contains_any",
                "contains_all"
              ]
            },
            "value": {
              "minItems": 1,
              "maxItems": 1000,
              "type": "array",
              "items": {
                "$ref": "#/$defs/Scalar"
              }
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "in_last_x_days",
                "in_next_x_days",
                "more_than_x_days_ago"
              ]
            },
            "value": {
              "$ref": "#/$defs/Days"
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "attribute"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "email",
                    "firstName",
                    "lastName",
                    "phone",
                    "status",
                    "source",
                    "locale",
                    "timezone",
                    "optinAt",
                    "createdAt",
                    "updatedAt"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^custom\\.[a-z][a-z0-9_]{0,62}$"
                }
              ]
            },
            "op": {
              "type": "string",
              "const": "anniversary"
            },
            "value": {
              "type": "object",
              "properties": {
                "offsetDays": {
                  "type": "integer",
                  "minimum": -365,
                  "maximum": 365
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "type",
            "field",
            "op"
          ],
          "additionalProperties": false
        }
      ]
    },
    "Scalar": {
      "type": [
        "string",
        "number",
        "boolean"
      ]
    },
    "Days": {
      "type": "integer",
      "minimum": 0,
      "maximum": 36500
    },
    "ListCondition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "list"
        },
        "id": {
          "$ref": "#/$defs/NodeId"
        },
        "negate": {
          "type": "boolean"
        },
        "op": {
          "type": "string",
          "enum": [
            "in",
            "not_in"
          ]
        },
        "value": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        "membershipStatus": {
          "type": "string",
          "enum": [
            "subscribed",
            "unsubscribed",
            "pending",
            "any"
          ]
        }
      },
      "required": [
        "type",
        "op",
        "value"
      ],
      "additionalProperties": false
    },
    "TagCondition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "tag"
        },
        "id": {
          "$ref": "#/$defs/NodeId"
        },
        "negate": {
          "type": "boolean"
        },
        "op": {
          "type": "string",
          "enum": [
            "has",
            "not_has"
          ]
        },
        "value": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      },
      "required": [
        "type",
        "op",
        "value"
      ],
      "additionalProperties": false
    },
    "SegmentCondition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "segment"
        },
        "id": {
          "$ref": "#/$defs/NodeId"
        },
        "negate": {
          "type": "boolean"
        },
        "op": {
          "type": "string",
          "enum": [
            "in",
            "not_in"
          ]
        },
        "value": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        }
      },
      "required": [
        "type",
        "op",
        "value"
      ],
      "additionalProperties": false
    },
    "EngagementCondition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "engagement"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "enum": [
                "opened_campaign",
                "not_opened_campaign",
                "clicked_campaign",
                "not_clicked_campaign",
                "received_campaign",
                "not_received_campaign"
              ]
            },
            "campaignId": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            "window": {
              "$ref": "#/$defs/Window"
            },
            "excludeMachineOpens": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "op",
            "campaignId"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "engagement"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "enum": [
                "opened_any",
                "not_opened_any",
                "clicked_any",
                "not_clicked_any",
                "received_any"
              ]
            },
            "window": {
              "$ref": "#/$defs/Window"
            },
            "excludeMachineOpens": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "engagement"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "enum": [
                "never_opened",
                "never_clicked"
              ]
            },
            "excludeMachineOpens": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "engagement"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "const": "clicked_link_containing"
            },
            "value": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            },
            "campaignId": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            "window": {
              "$ref": "#/$defs/Window"
            }
          },
          "required": [
            "type",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "const": "engagement"
                },
                "id": {
                  "$ref": "#/$defs/NodeId"
                },
                "negate": {
                  "type": "boolean"
                },
                "op": {
                  "type": "string",
                  "const": "engagement_score"
                },
                "comparison": {
                  "type": "string",
                  "enum": [
                    "gt",
                    "gte",
                    "lt",
                    "lte"
                  ]
                },
                "value": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                }
              },
              "required": [
                "type",
                "op",
                "comparison",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "const": "engagement"
                },
                "id": {
                  "$ref": "#/$defs/NodeId"
                },
                "negate": {
                  "type": "boolean"
                },
                "op": {
                  "type": "string",
                  "const": "engagement_score"
                },
                "comparison": {
                  "type": "string",
                  "const": "between"
                },
                "value": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 100
                    },
                    {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 100
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                }
              },
              "required": [
                "type",
                "op",
                "comparison",
                "value"
              ],
              "additionalProperties": false
            }
          ]
        }
      ]
    },
    "Window": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "lastDays": {
              "type": "integer",
              "minimum": 1,
              "maximum": 3650
            }
          },
          "required": [
            "lastDays"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "from": {
              "$ref": "#/$defs/DateTime"
            },
            "to": {
              "$ref": "#/$defs/DateTime"
            }
          },
          "required": [
            "from",
            "to"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "after": {
              "$ref": "#/$defs/DateTime"
            }
          },
          "required": [
            "after"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "before": {
              "$ref": "#/$defs/DateTime"
            }
          },
          "required": [
            "before"
          ],
          "additionalProperties": false
        }
      ]
    },
    "DateTime": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "EventCondition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "event"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "event": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.]{0,99}$"
            },
            "window": {
              "$ref": "#/$defs/Window"
            },
            "where": {
              "maxItems": 20,
              "type": "array",
              "items": {
                "$ref": "#/$defs/PropertyFilter"
              }
            },
            "aggregate": {
              "$ref": "#/$defs/EventAggregate"
            },
            "op": {
              "type": "string",
              "enum": [
                "has_done",
                "has_not_done"
              ]
            }
          },
          "required": [
            "type",
            "event",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "event"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "event": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.]{0,99}$"
            },
            "window": {
              "$ref": "#/$defs/Window"
            },
            "where": {
              "maxItems": 20,
              "type": "array",
              "items": {
                "$ref": "#/$defs/PropertyFilter"
              }
            },
            "aggregate": {
              "$ref": "#/$defs/EventAggregate"
            },
            "op": {
              "type": "string",
              "enum": [
                "count_gte",
                "count_lte",
                "count_eq"
              ]
            },
            "value": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "required": [
            "type",
            "event",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "event"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "event": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.]{0,99}$"
            },
            "window": {
              "$ref": "#/$defs/Window"
            },
            "where": {
              "maxItems": 20,
              "type": "array",
              "items": {
                "$ref": "#/$defs/PropertyFilter"
              }
            },
            "aggregate": {
              "$ref": "#/$defs/EventAggregate"
            },
            "op": {
              "type": "string",
              "const": "count_between"
            },
            "value": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              ],
              "items": false,
              "minItems": 2,
              "maxItems": 2
            }
          },
          "required": [
            "type",
            "event",
            "op",
            "value"
          ],
          "additionalProperties": false
        }
      ]
    },
    "PropertyFilter": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "enum": [
                "is_empty",
                "is_not_empty"
              ]
            }
          },
          "required": [
            "property",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "enum": [
                "equals",
                "not_equals",
                "contains",
                "not_contains",
                "starts_with",
                "ends_with",
                "gt",
                "gte",
                "lt",
                "lte",
                "before",
                "after",
                "on"
              ]
            },
            "value": {
              "$ref": "#/$defs/Scalar"
            }
          },
          "required": [
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "const": "between"
            },
            "value": {
              "type": "array",
              "prefixItems": [
                {
                  "type": [
                    "number",
                    "string"
                  ]
                },
                {
                  "type": [
                    "number",
                    "string"
                  ]
                }
              ],
              "items": false,
              "minItems": 2,
              "maxItems": 2
            }
          },
          "required": [
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "enum": [
                "in",
                "not_in",
                "contains_any",
                "contains_all"
              ]
            },
            "value": {
              "minItems": 1,
              "maxItems": 1000,
              "type": "array",
              "items": {
                "$ref": "#/$defs/Scalar"
              }
            }
          },
          "required": [
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "enum": [
                "in_last_x_days",
                "in_next_x_days",
                "more_than_x_days_ago"
              ]
            },
            "value": {
              "$ref": "#/$defs/Days"
            }
          },
          "required": [
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "const": "anniversary"
            },
            "value": {
              "type": "object",
              "properties": {
                "offsetDays": {
                  "type": "integer",
                  "minimum": -365,
                  "maximum": 365
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "property",
            "op"
          ],
          "additionalProperties": false
        }
      ]
    },
    "PropertyPath": {
      "type": "string",
      "pattern": "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*){0,4}$"
    },
    "EventAggregate": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "fn": {
              "type": "string",
              "enum": [
                "sum",
                "avg",
                "min",
                "max"
              ]
            },
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "enum": [
                "gt",
                "gte",
                "lt",
                "lte",
                "equals"
              ]
            },
            "value": {
              "type": "number"
            }
          },
          "required": [
            "fn",
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "fn": {
              "type": "string",
              "enum": [
                "sum",
                "avg",
                "min",
                "max"
              ]
            },
            "property": {
              "$ref": "#/$defs/PropertyPath"
            },
            "op": {
              "type": "string",
              "const": "between"
            },
            "value": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "number"
                },
                {
                  "type": "number"
                }
              ],
              "items": false,
              "minItems": 2,
              "maxItems": 2
            }
          },
          "required": [
            "fn",
            "property",
            "op",
            "value"
          ],
          "additionalProperties": false
        }
      ]
    },
    "EcommerceCondition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "totalSpentCents",
                "ordersCount",
                "averageOrderValueCents",
                "firstOrderAt",
                "lastOrderAt"
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "is_empty",
                "is_not_empty"
              ]
            }
          },
          "required": [
            "type",
            "field",
            "op"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "totalSpentCents",
                "ordersCount",
                "averageOrderValueCents",
                "firstOrderAt",
                "lastOrderAt"
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "equals",
                "gt",
                "gte",
                "lt",
                "lte",
                "before",
                "after"
              ]
            },
            "value": {
              "$ref": "#/$defs/Scalar"
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "totalSpentCents",
                "ordersCount",
                "averageOrderValueCents",
                "firstOrderAt",
                "lastOrderAt"
              ]
            },
            "op": {
              "type": "string",
              "const": "between"
            },
            "value": {
              "type": "array",
              "prefixItems": [
                {
                  "type": [
                    "number",
                    "string"
                  ]
                },
                {
                  "type": [
                    "number",
                    "string"
                  ]
                }
              ],
              "items": false,
              "minItems": 2,
              "maxItems": 2
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "totalSpentCents",
                "ordersCount",
                "averageOrderValueCents",
                "firstOrderAt",
                "lastOrderAt"
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "in_last_x_days",
                "more_than_x_days_ago"
              ]
            },
            "value": {
              "$ref": "#/$defs/Days"
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "enum": [
                "purchased_product",
                "not_purchased_product",
                "purchased_category",
                "not_purchased_category"
              ]
            },
            "value": {
              "minItems": 1,
              "maxItems": 500,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            },
            "window": {
              "$ref": "#/$defs/Window"
            }
          },
          "required": [
            "type",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "ecommerce"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "op": {
              "type": "string",
              "const": "has_abandoned_cart"
            },
            "idleHours": {
              "type": "integer",
              "minimum": 1,
              "maximum": 720
            },
            "window": {
              "$ref": "#/$defs/Window"
            }
          },
          "required": [
            "type",
            "op"
          ],
          "additionalProperties": false
        }
      ]
    },
    "AutomationCondition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "automation"
        },
        "id": {
          "$ref": "#/$defs/NodeId"
        },
        "negate": {
          "type": "boolean"
        },
        "op": {
          "type": "string",
          "enum": [
            "is_in",
            "was_in",
            "completed",
            "never_entered"
          ]
        },
        "value": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        "window": {
          "$ref": "#/$defs/Window"
        }
      },
      "required": [
        "type",
        "op",
        "value"
      ],
      "additionalProperties": false
    },
    "SourceCondition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "source"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "source"
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "equals",
                "not_equals"
              ]
            },
            "value": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "source"
            },
            "id": {
              "$ref": "#/$defs/NodeId"
            },
            "negate": {
              "type": "boolean"
            },
            "field": {
              "type": "string",
              "enum": [
                "source"
              ]
            },
            "op": {
              "type": "string",
              "enum": [
                "in",
                "not_in"
              ]
            },
            "value": {
              "minItems": 1,
              "maxItems": 1000,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              }
            }
          },
          "required": [
            "type",
            "field",
            "op",
            "value"
          ],
          "additionalProperties": false
        }
      ]
    }
  }
}
