{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "title": "After User Created Or Updated Trigger Context",
  "description": "Defines the trigger variables available to an AFTER_USER_CREATED_OR_UPDATED trigger",
  "properties": {
    "type": {
      "enum": [
        "AFTER_USER_CREATED_OR_UPDATED"
      ]
    },
    "user": {
      "title": "Current User",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "title": "User Id"
        },
        "accountId": {
          "type": "string",
          "title": "Account Id"
        },
        "firstName": {
          "type": [
            "string",
            "null"
          ],
          "title": "First Name"
        },
        "lastName": {
          "type": [
            "string",
            "null"
          ],
          "title": "Last Name"
        },
        "imageUrl": {
          "type": [
            "string",
            "null"
          ],
          "title": "Image Url"
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "title": "Email Address"
        },
        "cookieId": {
          "type": [
            "string",
            "null"
          ],
          "title": "Cookie Id"
        },
        "locale": {
          "type": [
            "string",
            "null"
          ],
          "title": "Locale"
        },
        "countryCode": {
          "type": [
            "string",
            "null"
          ],
          "title": "Country Code"
        },
        "referable": {
          "type": "boolean",
          "title": "Is Referable"
        },
        "firstSeenIP": {
          "type": [
            "string",
            "null"
          ],
          "title": "First Seen IP Address"
        },
        "lastSeenIP": {
          "type": [
            "string",
            "null"
          ],
          "title": "Last Seen IP Address"
        },
        "dateCreated": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Created"
        },
        "dateBlocked": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Blocked"
        },
        "customFields": {
          "$ref": "#/definitions/customFieldsContext"
        },
        "segments": {
          "type": "array",
          "title": "Segments",
          "description": "A list of segments this user has been assigned to",
          "items": {
            "type": "string",
            "title": "Segment Key",
            "description": "A segment key this user has been assigned to (e.g. VIP)"
          }
        },
        "fraudFlags": {
          "type": "array",
          "title": "Fraud Flags",
          "description": "Flags indicating whether this user was marked as a potentially fradulent user",
          "items": {
            "type": "object",
            "title": "Fraud Flag",
            "properties": {
              "type": {
                "type": "string",
                "title": "Flag Type",
                "enum": [
                  "IP",
                  "EMAIL",
                  "NAME",
                  "RATE",
                  "DAILY_REFERRAL_REWARD_LIMIT",
                  "TEMP_EMAIL",
                  "BLOCKED_USER",
                  "BLOCKED_IP"
                ]
              },
              "message": {
                "type": "string",
                "title": "Flag Description"
              }
            },
            "required": [
              "type",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "rewards": {
          "type": "object",
          "title": "Rewards",
          "properties": {
            "totalCount": {
              "type": "integer",
              "title": "Total Count",
              "description": "The number of rewards this user has received"
            },
            "data": {
              "type": "array",
              "title": "The Data Schema",
              "description": "A list of the rewards this user has received (up to 20)",
              "items": {
                "type": "object",
                "title": "Reward",
                "description": "The set of reward fields",
                "properties": {
                  "id": {
                    "type": "string",
                    "title": "Reward Id",
                    "description": "The reward identifier"
                  },
                  "dateGiven": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Given",
                    "description": "The date the reward was given"
                  },
                  "dateExpires": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Expires",
                    "description": "The date the reward expires"
                  },
                  "dateCancelled": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Cancelled",
                    "description": "The date the reward was cancelled"
                  },
                  "programId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Program Id",
                    "description": "The identifier of the program that generated this reward"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Program Reward Key",
                    "description": "The reward key assigned by the program that generated this reward"
                  },
                  "referralId": {
                    "type": "string",
                    "title": "Referral Id",
                    "description": "The referral identifier assocaited with this reward"
                  }
                }
              }
            }
          },
          "required": [
            "totalCount",
            "data"
          ],
          "additionalProperties": false
        },
        "referrals": {
          "type": "object",
          "title": "The Referrals Schema",
          "required": [
            "totalCount"
          ],
          "properties": {
            "totalCount": {
              "type": "integer",
              "title": "Total Count",
              "description": "The number of referrals this user has made"
            }
          }
        },
        "referredByReferral": {
          "type": "object",
          "title": "Referred By Referral",
          "description": "The referral where this user was referred. Null when not a referral or partner program.",
          "properties": {
            "id": {
              "type": "string",
              "title": "Referral Id",
              "description": "The unique identifier for this referral"
            },
            "dateReferralStarted": {
              "type": "integer",
              "title": "Date Referral Started",
              "description": "The date this referral was created (attributed)"
            },
            "referrerUser": {
              "type": "object",
              "title": "Referrer",
              "description": "The referring user, the one that referred the current user",
              "properties": {
                "id": {
                  "type": "string",
                  "title": "User Id"
                },
                "accountId": {
                  "type": "string",
                  "title": "Account Id"
                },
                "firstName": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "First Name"
                },
                "lastName": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Last Name"
                },
                "imageUrl": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Image Url"
                },
                "email": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Email Address"
                },
                "cookieId": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Cookie Id"
                },
                "locale": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Locale"
                },
                "countryCode": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Country Code"
                },
                "referable": {
                  "type": "boolean",
                  "title": "Is Referable"
                },
                "firstSeenIP": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "First Seen IP Address"
                },
                "lastSeenIP": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "Last Seen IP Address"
                },
                "dateCreated": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "title": "Date User Created"
                },
                "dateBlocked": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "title": "Date User Blocked"
                },
                "customFields": {
                  "$ref": "#/definitions/customFieldsContext"
                },
                "segments": {
                  "type": "array",
                  "title": "Segments",
                  "description": "A list of segments this user has been assigned to",
                  "items": {
                    "type": "string",
                    "title": "Segment Key",
                    "description": "A segment key this user has been assigned to (e.g. VIP)"
                  }
                },
                "fraudFlags": {
                  "type": "array",
                  "title": "Fraud Flags",
                  "description": "Flags indicating whether this user was marked as a potentially fradulent user",
                  "items": {
                    "type": "object",
                    "title": "Fraud Flag",
                    "properties": {
                      "type": {
                        "type": "string",
                        "title": "Flag Type",
                        "enum": [
                          "IP",
                          "EMAIL",
                          "NAME",
                          "RATE",
                          "DAILY_REFERRAL_REWARD_LIMIT",
                          "TEMP_EMAIL",
                          "BLOCKED_USER",
                          "BLOCKED_IP"
                        ]
                      },
                      "message": {
                        "type": "string",
                        "title": "Flag Description"
                      }
                    },
                    "required": [
                      "type",
                      "message"
                    ],
                    "additionalProperties": false
                  }
                }
              }
            },
            "rewards": {
              "type": "array",
              "title": "Referral Rewards",
              "description": "A list of rewards associated with this referral",
              "items": {
                "type": "object",
                "title": "Reward",
                "description": "The set of reward fields",
                "properties": {
                  "id": {
                    "type": "string",
                    "title": "Reward Id",
                    "description": "The reward identifier"
                  },
                  "dateGiven": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Given",
                    "description": "The date the reward was given"
                  },
                  "dateExpires": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Expires",
                    "description": "The date the reward expires"
                  },
                  "dateCancelled": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Date Cancelled",
                    "description": "The date the reward was cancelled"
                  },
                  "programId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "title": "Program Id",
                    "description": "The identifier of the program that generated this reward"
                  },
                  "programRewardKey": {
                    "type": "string",
                    "title": "Program Reward Key",
                    "description": "The reward key assigned by the program that generated this reward"
                  },
                  "referralId": {
                    "type": "string",
                    "title": "Referral Id",
                    "description": "The referral identifier assocaited with this reward"
                  }
                }
              }
            }
          }
        }
      }
    },
    "previous": {
      "title": "Previous User",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "title": "User Id"
        },
        "accountId": {
          "type": "string",
          "title": "Account Id"
        },
        "firstName": {
          "type": [
            "string",
            "null"
          ],
          "title": "First Name"
        },
        "lastName": {
          "type": [
            "string",
            "null"
          ],
          "title": "Last Name"
        },
        "imageUrl": {
          "type": [
            "string",
            "null"
          ],
          "title": "Image Url"
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "title": "Email Address"
        },
        "cookieId": {
          "type": [
            "string",
            "null"
          ],
          "title": "Cookie Id"
        },
        "locale": {
          "type": [
            "string",
            "null"
          ],
          "title": "Locale"
        },
        "countryCode": {
          "type": [
            "string",
            "null"
          ],
          "title": "Country Code"
        },
        "referable": {
          "type": "boolean",
          "title": "Is Referable"
        },
        "firstSeenIP": {
          "type": [
            "string",
            "null"
          ],
          "title": "First Seen IP Address"
        },
        "lastSeenIP": {
          "type": [
            "string",
            "null"
          ],
          "title": "Last Seen IP Address"
        },
        "dateCreated": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Created"
        },
        "dateBlocked": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Blocked"
        },
        "customFields": {
          "$ref": "#/definitions/customFieldsContext"
        },
        "segments": {
          "type": "array",
          "title": "Segments",
          "description": "A list of segments this user has been assigned to",
          "items": {
            "type": "string",
            "title": "Segment Key",
            "description": "A segment key this user has been assigned to (e.g. VIP)"
          }
        },
        "fraudFlags": {
          "type": "array",
          "title": "Fraud Flags",
          "description": "Flags indicating whether this user was marked as a potentially fradulent user",
          "items": {
            "type": "object",
            "title": "Fraud Flag",
            "properties": {
              "type": {
                "type": "string",
                "title": "Flag Type",
                "enum": [
                  "IP",
                  "EMAIL",
                  "NAME",
                  "RATE",
                  "DAILY_REFERRAL_REWARD_LIMIT",
                  "TEMP_EMAIL",
                  "BLOCKED_USER",
                  "BLOCKED_IP"
                ]
              },
              "message": {
                "type": "string",
                "title": "Flag Description"
              }
            },
            "required": [
              "type",
              "message"
            ],
            "additionalProperties": false
          }
        }
      }
    },
    "time": {
      "type": "integer",
      "title": "Trigger Time",
      "description": "The current time at the moment the program is evaluated"
    }
  },
  "definitions": {
    "eventContext": {
      "type": "object",
      "title": "Event",
      "description": "The variables for the event that triggered the program",
      "properties": {
        "key": {
          "type": "string",
          "title": "Event Key",
          "description": "The key of the evaluated event (e.g. purchase)"
        },
        "dateTriggered": {
          "type": "integer",
          "title": "Date Triggered",
          "description": "The date this event was created"
        },
        "fields": {
          "$ref": "#/definitions/eventFieldsContext"
        }
      }
    },
    "eventFieldsContext": {
      "type": "object",
      "title": "Event Fields",
      "description": "The body of the event (e.g. a purchase event would have fields for revenue, currency, etc.)"
    },
    "customFieldsContext": {
      "$schema": "http://json-schema.org/draft-06/schema#",
      "title": "User Custom Fields Schema",
      "description": "Defines how custom fields can be specified on a user. Allows alphanumeric numbers and underscores.",
      "type": "object",
      "patternProperties": {
        "^[a-zA-Z0-9_]{1,64}$": {
          "$schema": "http://json-schema.org/draft-06/schema#",
          "anyOf": [
            {
              "type": "string",
              "maxLength": 1024
            },
            {
              "type": "boolean"
            },
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "maxProperties": 100
    }
  }
}