{
  "name": "Referral Program With Objectives",
  "emails": [],
  "rewards": [],
  "sharing": {
    "enabled": true,
    "linksConfig": {
      "defaults": "linkConfigId"
    }
  },
  "summary": "Reward people for making referrals",
  "trigger": {
    "eventKeys": []
  },
  "widgets": [
    {
      "key": "referrerWidget",
      "name": "In-app referral widget",
      "defaults": "referrerWidgetId",
      "description": "Widget displayed to a user who has referred friends",
      "supportsInstantAccess": false
    },
    {
      "key": "websiteReferralWidget",
      "name": "Website referral widget",
      "defaults": "websiteReferralWidgetId",
      "description": "The website referrer widget allows participants to get instant access to their share link without providing full login credentials. ",
      "supportsInstantAccess": true
    },
    {
      "key": "friendWidget",
      "name": "Friend widget",
      "defaults": "friendWidgetId",
      "description": "Widget displayed to a referred friend",
      "supportsInstantAccess": true
    }
  ],
  "requirements": [
    {
      "key": "conversionTrigger",
      "name": "Conversion Trigger",
      "query": null,
      "description": "This is used to validate that a program's conversion trigger is functioning before launch.",
      "longDescription": null
    },
    {
      "key": "uniqueKeys",
      "name": "Unique Keys",
      "query": null,
      "description": "This is used to validate that a program's unique keys are all unique.",
      "longDescription": null
    },
    {
      "key": "validJsonata",
      "name": "Valid JSONata",
      "query": null,
      "description": "This is used to validate that a program's rules contain valid JSONata expressions.",
      "longDescription": null
    }
  ],
  "rulesUISchema": {
    "version": {
      "ui:widget": "hidden"
    },
    "conversionRule": {
      "objectives": {
        "items": {
          "ID": {
            "ui:title": "Stage ID",
            "ui:widget": "UUIDWidget"
          },
          "key": {
            "ui:title": "Goal Key",
            "ui:widget": "KeyInput",
            "ui:options": {
              "generator": "parent.name",
              "namespace": "p2.key"
            },
            "ui:description": "Once saved the goal key cannot be changed."
          },
          "name": {
            "ui:widget": "hidden"
          },
          "firstTimeOnly": {
            "ui:widget": "hidden"
          },
          "actions": {
            "items": {
              "key": {
                "ui:title": "Action Key",
                "ui:widget": "KeyInput",
                "ui:options": {
                  "generator": "parent.name",
                  "namespace": "p2.key"
                },
                "ui:description": "Once saved the action key cannot be changed."
              },
              "name": {
                "ui:widget": "hidden"
              },
              "firstTimeOnly": {
                "ui:widget": "hidden"
              },
              "reward": {
                "unit": {
                  "ui:title": "Unit",
                  "ui:widget": "JSONataUnit"
                },
                "value": {
                  "ui:title": "Value",
                  "ui:widget": "JSONataAmount",
                  "ui:options": {
                    "generator": "parent.unit"
                  }
                },
                "ui:order": [
                  "key",
                  "rewardType",
                  "unit",
                  "value",
                  "expiryDate",
                  "pendingPeriod"
                ],
                "expiryDate": {
                  "ui:title": "Reward Expiration",
                  "ui:widget": "JSONataDate",
                  "ui:options": {
                    "dateLabel": "Fixed Date",
                    "emptyLabel": "Never expires",
                    "formulaLabel": "Formula",
                    "durationLabel": "Duration",
                    "dateDescription": "Expire the reward on a set date.",
                    "emptyDescription": "No expiry date will be set on the reward",
                    "formulaDescription": "Set when the reward expires using a custom formula.",
                    "durationDescription": "Expire the reward after a set period of time."
                  },
                  "ui:description": "Choose if and when the reward expires."
                },
                "rewardType": {
                  "ui:title": "Reward",
                  "ui:widget": "RadioAsCards",
                  "ui:options": {
                    "ruleOptions": [
                      {
                        "key": "static",
                        "icon": "hand_money",
                        "title": "Fixed Reward",
                        "description": "The reward given always has the same value."
                      },
                      {
                        "key": "dynamic",
                        "icon": "sparkles",
                        "title": "Dynamic Reward",
                        "description": "Create a custom reward with a dynamic value and/or unit."
                      }
                    ]
                  }
                },
                "pendingPeriod": {
                  "ui:title": "Reward Pending",
                  "ui:widget": "JSONataDate",
                  "ui:options": {
                    "dateLabel": "Fixed Date",
                    "emptyLabel": "Immediately available",
                    "formulaLabel": "Formula",
                    "durationLabel": "Duration",
                    "dateDescription": "Keep the reward as pending until a set date.",
                    "emptyDescription": "The reward will be immediately available to the user",
                    "formulaDescription": "Set the time a reward should be kept as pending using a custom formula.",
                    "durationDescription": "Keep the reward as pending for a set period of time."
                  },
                  "ui:description": "Add a pending period as a safety buffer in case your participant no longer qualifies for this reward. Example: Only give out this reward after your return period has ended."
                }
              },
              "subType": {
                "ui:title": "Retraction Type",
                "ui:widget": "RadioAsCards",
                "ui:options": {
                  "ruleOptions": [
                    {
                      "key": "rewards",
                      "icon": "retract_reward",
                      "title": "Reward Retraction",
                      "description": "Retract specific rewards"
                    },
                    {
                      "key": "referral",
                      "icon": "retract_referral",
                      "title": "Referral Retraction",
                      "description": "Retract all rewards for the referral"
                    },
                    {
                      "key": "event",
                      "icon": "retract_event",
                      "title": "Event Retraction",
                      "description": "Retract the rewards caused by a specific event"
                    },
                    {
                      "key": "event",
                      "icon": "retract_referral",
                      "title": "Conversion Retraction",
                      "description": "Revert a converted referral. It can be converted again later and participants can still redeem any rewards linked to it"
                    }
                  ]
                }
              },
              "audience": {
                "ui:title": "Audience",
                "ui:widget": "RadioAsCards",
                "ui:options": {
                  "ruleOptions": [
                    {
                      "key": "referrer",
                      "icon": "person_audience",
                      "title": "Referrer",
                      "description": "The user who initiated the referral."
                    },
                    {
                      "key": "referred",
                      "icon": "person_arrows",
                      "title": "Referred User",
                      "description": "The user who was referred."
                    }
                  ]
                }
              },
              "ui:order": [
                "name",
                "key",
                "actionType",
                "audience",
                "condition",
                "email",
                "sourceUnit",
                "sourceValue",
                "globalRewardKey",
                "repeatExchange",
                "*"
              ],
              "condition": {
                "ui:title": "Action Criteria",
                "ui:widget": "JSONataCondition",
                "ui:options": {
                  "text": {
                    "title": "Condition",
                    "addRule": "Add Rule",
                    "invalidText": "This action condition uses custom logic and may not complete on the goals first time or every time. Switch to the advanced editor to make changes.",
                    "addCondition": "Add Condition",
                    "everyTimeText": "Perform this action every time the participant triggers this goal and meets the conditions in this rule.",
                    "firstTimeText": "Perform this action if the participant hasn't completed this goal before and they meet the conditions in this rule.",
                    "emptyStateButton": "Add Rule"
                  },
                  "grouped": true,
                  "generator": "p3.trigger.eventKey",
                  "rewardKey": "referrerReward",
                  "goalIsFirstTime": true,
                  "canCreateCalculatedField": true
                },
                "ui:description": "Only perform this action if the following rules are satisfied. Build your rules using custom fields, calculated fields, goals, and more. "
              },
              "actionType": {
                "ui:title": "Action Type",
                "ui:description": "To help prevent fraudulent usage, we recommend giving only giving out rewards for goals that generate revenue.",
                "ui:widget": "RadioAsCards",
                "ui:options": {
                  "columns": 2,
                  "ruleOptions": [
                    {
                      "key": "tieredRewardsAndEmail",
                      "icon": "podium_star",
                      "title": "Tiered Rewards and Email",
                      "description": "Give a tiered reward and send an email to your audience."
                    },
                    {
                      "key": "rewardAndEmail",
                      "icon": "gift",
                      "title": "Reward and Email",
                      "description": "Give a reward and send an email to your audience."
                    },
                    {
                      "key": "email",
                      "icon": "mail",
                      "title": "Email",
                      "description": "Send an email to your audience."
                    },
                    {
                      "key": "exchangeReward",
                      "icon": "exchange",
                      "title": "Exchange Reward",
                      "description": "Exchange a reward unit for a predefined reward."
                    },
                    {
                      "key": "retraction",
                      "icon": "block_gift",
                      "title": "Retraction",
                      "description": "Retract rewards, referrals, events, or conversions for participants who no longer qualify."
                    }
                  ]
                }
              },
              "sourceUnit": {
                "ui:title": "Source Unit",
                "ui:widget": "JSONataUnit",
                "ui:description": "The reward unit exchanged."
              },
              "rewardTiers": {
                "items": {
                  "key": {
                    "ui:title": "Tier Key",
                    "ui:widget": "UUIDWidget",
                    "ui:options": {
                      "visible": true
                    }
                  },
                  "reward": {
                    "unit": {
                      "ui:title": "Unit",
                      "ui:widget": "JSONataUnit"
                    },
                    "value": {
                      "ui:title": "Value",
                      "ui:widget": "JSONataAmount",
                      "ui:options": {
                        "generator": "parent.unit"
                      }
                    },
                    "ui:order": [
                      "key",
                      "rewardType",
                      "unit",
                      "value",
                      "expiryDate",
                      "pendingPeriod"
                    ],
                    "expiryDate": {
                      "ui:title": "Reward Expiration",
                      "ui:widget": "JSONataDate",
                      "ui:options": {
                        "dateLabel": "Fixed Date",
                        "emptyLabel": "Never expires",
                        "formulaLabel": "Formula",
                        "durationLabel": "Duration",
                        "dateDescription": "Expire the reward on a set date.",
                        "emptyDescription": "No expiry date will be set on the reward",
                        "formulaDescription": "Set when the reward expires using a custom formula.",
                        "durationDescription": "Expire the reward after a set period of time."
                      },
                      "ui:description": "Choose if and when the reward expires."
                    },
                    "rewardType": {
                      "ui:title": "Reward",
                      "ui:widget": "RadioAsCards",
                      "ui:options": {
                        "ruleOptions": [
                          {
                            "key": "static",
                            "icon": "gift",
                            "title": "Fixed Reward",
                            "description": "The reward given will always have the same value."
                          },
                          {
                            "key": "dynamic",
                            "icon": "sparkles",
                            "title": "Dynamic Reward",
                            "description": "Create a custom reward with a dynamic value and/or unit."
                          }
                        ]
                      }
                    },
                    "pendingPeriod": {
                      "ui:title": "Reward Pending",
                      "ui:widget": "JSONataDate",
                      "ui:options": {
                        "dateLabel": "Fixed Date",
                        "emptyLabel": "Immediately available",
                        "formulaLabel": "Formula",
                        "durationLabel": "Duration",
                        "dateDescription": "Keep the reward as pending until a set date.",
                        "emptyDescription": "The reward will be immediately available to the user",
                        "formulaDescription": "Set the time a reward should be kept as pending using a custom formula.",
                        "durationDescription": "Keep the reward as pending for a set period of time."
                      },
                      "ui:description": "Choose if and for how long a reward should be marked as pending before it is given."
                    },
                    "overrideEmailKey": {
                      "ui:widget": "hidden"
                    },
                    "overrideRewardKey": {
                      "ui:widget": "hidden"
                    }
                  },
                  "ui:order": [
                    "key",
                    "rewardType",
                    "condition",
                    "unit",
                    "value",
                    "expiryDate",
                    "pendingPeriod",
                    "*"
                  ],
                  "condition": {
                    "ui:title": "Reward Condition",
                    "ui:widget": "JSONataCondition",
                    "ui:options": {
                      "text": {
                        "title": "Condition",
                        "addRule": "Add Rule",
                        "addCondition": "Add Condition",
                        "emptyStateButton": "Add Rule"
                      },
                      "grouped": true,
                      "generator": "p5.trigger.eventKey",
                      "canCreateCalculatedField": true
                    },
                    "ui:description": "This reward will only be given if this condition is met."
                  },
                  "overrideRewardKey": {
                    "ui:widget": "hidden"
                  }
                },
                "ui:options": {
                  "name": "reward",
                  "title": "Reward Tiers",
                  "editText": "Edit",
                  "stepIcon": "gift",
                  "themeColor": "#f5a841",
                  "defaultName": "Tier",
                  "description": "Users will be given the reward from the first tier where the reward condition is met.",
                  "collapseText": "Done",
                  "addButtonText": "Add Reward",
                  "stepIconStyle": "font-size:16px;margin-left:-2px;margin-top:2px;"
                },
                "ui:ArrayFieldTemplate": "MultiStepTemplate"
              },
              "sourceValue": {
                "ui:title": "Source Value",
                "ui:widget": "JSONataAmount",
                "ui:options": {
                  "generator": "parent.sourceUnit"
                },
                "ui:description": "The amount of source units exchanged."
              },
              "dependencies": {
                "ui:title": "Dependencies"
              },
              "repeatExchange": {
                "ui:title": "Repeat Exchange",
                "ui:description": "Optionally repeat the exchange until the user runs out of the source unit or has less than the source value required."
              },
              "sourceEventKey": {
                "ui:title": "Source Event Key",
                "ui:widget": "SelectKeyWidget"
              },
              "globalRewardKey": {
                "ui:title": "Destination Reward",
                "ui:widget": "GlobalRewardSelector",
                "ui:description": "Select the reward to exchange the source for."
              },
              "overrideEmailKey": {
                "ui:widget": "hidden"
              },
              "overrideRewardKey": {
                "ui:widget": "hidden"
              },
              "sourceEventFilter": {
                "ui:title": "Source Event Filter",
                "ui:widget": "JSONataConditionObject",
                "ui:options": {
                  "text": {
                    "title": "Rules",
                    "addRule": "Add Rule",
                    "grouped": true,
                    "addCondition": "Add Condition",
                    "emptyStateButton": "Add Rule"
                  },
                  "generator": "parent.sourceEventKey"
                }
              },
              "retractedRewardKeys": {
                "ui:title": "Retracted Reward Keys",
                "ui:options": {
                  "list": "rewards",
                  "label": "name",
                  "value": "key"
                },
                "ui:ArrayFieldTemplate": "IntrospectionKeyWidget"
              }
            },
            "ui:options": {
              "name": "action",
              "title": "Goal Actions",
              "editText": "Edit",
              "stepIcon": "rocket",
              "themeColor": "#f5a841",
              "description": "Decide what happens after the goal is completed by setting up Actions.",
              "collapseText": "Done",
              "addButtonText": "Add Action",
              "stepIconStyle": "font-size:16px;margin-left:-2px;margin-top:2px;"
            },
            "ui:ArrayFieldTemplate": "MultiStepTemplate"
          },
          "trigger": {
            "eventKey": {
              "ui:title": "Event Keys",
              "ui:widget": "SelectKeyWidget",
              "ui:description": "Trigger this goal when the selected event occurs. To help prevent fraudulent usage, we recommend only rewarding participants for events that generate revenue."
            },
            "ui:order": [
              "triggerType",
              "eventKey",
              "edgeFields",
              "condition",
              "*"
            ],
            "condition": {
              "ui:title": "Goal Criteria",
              "ui:widget": "JSONataCondition",
              "ui:options": {
                "text": {
                  "title": "Condition",
                  "addRule": "Add Rule",
                  "invalidText": "This goal condition uses custom logic and may not complete on first time or every time. Switch to the advanced editor to make changes.",
                  "addCondition": "Add Condition",
                  "everyTimeText": "Complete this goal every time the participant triggers this goal and meets the conditions in this rule.",
                  "firstTimeText": "Complete this goal if the participant hasn't completed it before and they meet the conditions in this rule.",
                  "emptyStateButton": "Add Rule"
                },
                "grouped": true,
                "generator": "parent.eventKey",
                "goalIsFirstTime": true,
                "canCreateCalculatedField": true
              },
              "ui:description": "After the goal is triggered, only consider this goal complete when at least one of the following rules is satisfied. Build your rules using data from custom fields, calculated fields, goals and more."
            },
            "edgeFields": {
              "ui:title": "Triggering User Fields",
              "ui:description": "Select user.segments and/or any user fields to trigger this goal when they are updated on a participant. To reduce the risk of fraud, consider rewarding participants only when updates to this field or segment directly lead to revenue generation.",
              "ui:ArrayFieldTemplate": "EdgeTriggerSection"
            },
            "triggerType": {
              "ui:title": "What triggers this goal?",
              "ui:widget": "RadioAsCards",
              "ui:options": {
                "ruleOptions": [
                  {
                    "key": "eventTrigger",
                    "icon": "hand_tap",
                    "title": "Referred user performs an action",
                    "description": "When the referred user performs an action tracked by an event, such as a purchase."
                  },
                  {
                    "key": "criteriaTrigger",
                    "icon": "id_card",
                    "title": "Referred user’s fields & segments",
                    "description": "When a user field, custom field, calculated field, or segment on the referred user’s profile is updated and meets your set criteria."
                  },
                  {
                    "key": "referralTrigger",
                    "icon": "people_pair",
                    "title": "On referral",
                    "description": "When a referral is started."
                  }
                ]
              }
            },
            "intent": {
              "ui:widget": "hidden"
            }
          },
          "ui:order": [
            "*",
            "actions"
          ],
          "performsConversion": {
            "ui:title": "Does completing this goal cause a conversion?",
            "ui:widget": "RadioAsCards",
            "ui:options": {
              "emptyValue": null,
              "ruleOptions": [
                {
                  "key": true,
                  "icon": "fuel_gauge",
                  "title": "Conversion goal",
                  "description": "The referral will be converted if this goal is completed."
                },
                {
                  "key": false,
                  "icon": "block",
                  "title": "Non-conversion goal",
                  "description": "Completing this goal will not convert the referral."
                }
              ]
            }
          },
          "referrerProgramRewardLimit": {
            "limitType": {
              "ui:title": "How many rewards is the referrer allowed to earn for this goal?",
              "ui:widget": "RadioAsCards",
              "ui:options": {
                "ruleOptions": [
                  {
                    "key": "unlimited",
                    "icon": "infinity",
                    "title": "Unlimited",
                    "description": "There is no limit on referrals made or rewards earned by the referrer."
                  },
                  {
                    "key": "limited",
                    "icon": "spinning_numbers",
                    "title": "Specific number of rewards",
                    "description": "The referrer can refer any number of friends, BUT you set the maximum number of rewards they can earn from this goal. Useful for stacking % discount rewards."
                  }
                ]
              }
            },
            "maxRewards": {
              "ui:title": "Reward Limit"
            },
            "overrideEmailKey": {
              "ui:widget": "hidden"
            },
            "overrideRewardKey": {
              "ui:widget": "hidden"
            }
          }
        },
        "ui:options": {
          "name": "goal",
          "title": "Program Goals",
          "editText": "Edit",
          "stepIcon": "target",
          "themeColor": "#f5a841",
          "description": "Referrals are converted when a conversion goal is completed. Goals can be completed in any order.",
          "collapseText": "Done",
          "addButtonText": "Add Goal",
          "stepIconStyle": "font-size:23px;margin-left:-10px;margin-top:-1px;"
        },
        "ui:ArrayFieldTemplate": "MultiStepTemplate"
      }
    }
  },
  "rules": {
    "self": {
      "name": "referral_rules_schema",
      "format": "jsonschema",
      "vendor": "saasquatch",
      "version": "4.0.0"
    },
    "type": "object",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
      "version": {
        "enum": [
          "4.0.0"
        ],
        "type": "string",
        "title": "Version of the current schema",
        "default": "4.0.0",
        "description": "The version property allows the JSONata migration script to perform a rules update when required"
      },
      "conversionRule": {
        "type": "object",
        "title": "Conversion Rules",
        "required": [
          "objectives"
        ],
        "properties": {
          "objectives": {
            "type": "array",
            "items": {
              "$ref": "#/definitions/objective"
            },
            "maxItems": 100,
            "minItems": 1
          }
        }
      }
    },
    "definitions": {
      "action": {
        "type": "object",
        "required": [
          "actionType",
          "name",
          "key"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9\\-_]*$"
          },
          "name": {
            "type": "string",
            "default": "Default Action Name"
          },
          "firstTimeOnly": {
            "type": "boolean"
          },
          "condition": {
            "type": "string"
          },
          "actionType": {
            "enum": [
              "tieredRewardsAndEmail",
              "rewardAndEmail",
              "email",
              "exchangeReward",
              "retraction"
            ],
            "type": "string",
            "enumNames": [
              "Tiered Rewards and Email",
              "Reward and Email",
              "Email",
              "Exchange Reward",
              "Retraction"
            ]
          }
        },
        "dependencies": {
          "actionType": {
            "oneOf": [
              {
                "required": [
                  "audience",
                  "rewardTiers"
                ],
                "properties": {
                  "audience": {
                    "$ref": "#/definitions/audience"
                  },
                  "actionType": {
                    "enum": [
                      "tieredRewardsAndEmail"
                    ]
                  },
                  "rewardTiers": {
                    "type": "array",
                    "items": {
                      "$ref": "#/definitions/rewardTier"
                    },
                    "maxItems": 100
                  },
                  "overrideEmailKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9\\-_]*$"
                  }
                }
              },
              {
                "required": [
                  "audience",
                  "reward"
                ],
                "properties": {
                  "reward": {
                    "$ref": "#/definitions/reward"
                  },
                  "audience": {
                    "$ref": "#/definitions/audience"
                  },
                  "actionType": {
                    "enum": [
                      "rewardAndEmail"
                    ]
                  },
                  "overrideEmailKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9\\-_]*$"
                  },
                  "overrideRewardKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9\\-_]*$"
                  }
                }
              },
              {
                "required": [
                  "audience"
                ],
                "properties": {
                  "audience": {
                    "$ref": "#/definitions/audience"
                  },
                  "actionType": {
                    "enum": [
                      "email"
                    ]
                  },
                  "overrideEmailKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9\\-_]*$"
                  }
                }
              },
              {
                "required": [
                  "subType"
                ],
                "properties": {
                  "subType": {
                    "enum": [
                      "rewards",
                      "referral",
                      "event",
                      "conversion"
                    ],
                    "enumNames": [
                      "Reward Retraction",
                      "Referral Retraction",
                      "Event Retraction",
                      "Conversion Retraction"
                    ]
                  },
                  "actionType": {
                    "enum": [
                      "retraction"
                    ]
                  }
                },
                "dependencies": {
                  "subType": {
                    "oneOf": [
                      {
                        "required": [
                          "retractedRewardKeys"
                        ],
                        "properties": {
                          "subType": {
                            "enum": [
                              "rewards"
                            ]
                          },
                          "retractedRewardKeys": {
                            "type": "array",
                            "items": {
                              "type": "string",
                              "pattern": "^[a-zA-Z0-9\\-_]*$"
                            },
                            "maxItems": 100,
                            "uniqueItems": true
                          }
                        }
                      },
                      {
                        "properties": {
                          "subType": {
                            "enum": [
                              "referral",
                              "conversion"
                            ]
                          }
                        }
                      },
                      {
                        "required": [
                          "sourceEventKey",
                          "sourceEventFilter"
                        ],
                        "properties": {
                          "subType": {
                            "enum": [
                              "event"
                            ]
                          },
                          "sourceEventKey": {
                            "type": "string"
                          },
                          "sourceEventFilter": {
                            "type": "string"
                          }
                        }
                      }
                    ]
                  }
                }
              },
              {
                "required": [
                  "audience",
                  "sourceUnit",
                  "sourceValue",
                  "globalRewardKey",
                  "repeatExchange"
                ],
                "properties": {
                  "audience": {
                    "$ref": "#/definitions/audience"
                  },
                  "actionType": {
                    "enum": [
                      "exchangeReward"
                    ]
                  },
                  "sourceUnit": {
                    "type": "string"
                  },
                  "sourceValue": {
                    "type": "string"
                  },
                  "repeatExchange": {
                    "enum": [
                      "no-repeat",
                      "repeat-max"
                    ],
                    "type": "string",
                    "enumNames": [
                      "Do not repeat",
                      "Repeat as many times as possible"
                    ]
                  },
                  "globalRewardKey": {
                    "type": "string"
                  }
                }
              }
            ]
          }
        }
      },
      "reward": {
        "type": "object",
        "required": [
          "rewardType"
        ],
        "properties": {
          "expiryDate": {
            "type": "string"
          },
          "rewardType": {
            "enum": [
              "static",
              "dynamic",
              "commission"
            ],
            "type": "string",
            "enumNames": [
              "Static Reward",
              "Dynamic Reward",
              "Commission"
            ]
          },
          "pendingPeriod": {
            "type": "string"
          }
        },
        "dependencies": {
          "rewardType": {
            "oneOf": [
              {
                "properties": {
                  "rewardType": {
                    "enum": [
                      "static"
                    ]
                  }
                }
              },
              {
                "required": [
                  "value",
                  "unit"
                ],
                "properties": {
                  "unit": {
                    "type": "string"
                  },
                  "value": {
                    "type": "string"
                  },
                  "rewardType": {
                    "enum": [
                      "dynamic"
                    ]
                  }
                }
              },
              {
                "required": [
                  "unit",
                  "commissionPercent"
                ],
                "properties": {
                  "unit": {
                    "type": "string"
                  },
                  "commissionPercent": {
                    "type": "integer"
                  },
                  "rewardType": {
                    "enum": [
                      "commission"
                    ]
                  }
                }
              }
            ]
          }
        }
      },
      "audience": {
        "enum": [
          "referrer",
          "referred"
        ],
        "type": "string",
        "enumNames": [
          "Referrer User",
          "Referred User"
        ]
      },
      "objective": {
        "type": "object",
        "required": [
          "key",
          "name",
          "trigger",
          "performsConversion"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9\\-_]*$"
          },
          "name": {
            "type": "string",
            "default": "Default Goal Name"
          },
          "actions": {
            "type": "array",
            "items": {
              "$ref": "#/definitions/action"
            },
            "maxItems": 100
          },
          "trigger": {
            "type": "object",
            "required": [
              "triggerType"
            ],
            "properties": {
              "triggerType": {
                "enum": [
                  "eventTrigger",
                  "criteriaTrigger",
                  "referralTrigger"
                ],
                "type": "string",
                "enumNames": [
                  "Event Trigger",
                  "Criteria Trigger",
                  "Referral Trigger"
                ]
              }
            },
            "dependencies": {
              "triggerType": {
                "oneOf": [
                  {
                    "required": [
                      "eventKey"
                    ],
                    "properties": {
                      "eventKey": {
                        "type": "string"
                      },
                      "intent": {
                        "type": "string",
                        "enum": [
                          "PURCHASE",
                          "REFUND",
                          "OTHER"
                        ],
                        "enumNames": [
                          "Purchase",
                          "Refund",
                          "Other"
                        ],
                        "default": "PURCHASE"
                      },
                      "firstTimeOnly": {
                        "type": "boolean"
                      },
                      "condition": {
                        "type": "string"
                      },
                      "triggerType": {
                        "enum": [
                          "eventTrigger"
                        ]
                      }
                    }
                  },
                  {
                    "properties": {
                      "firstTimeOnly": {
                        "type": "boolean"
                      },
                      "condition": {
                        "type": "string"
                      },
                      "edgeFields": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "triggerType": {
                        "enum": [
                          "criteriaTrigger"
                        ]
                      }
                    }
                  },
                  {
                    "properties": {
                      "firstTimeOnly": {
                        "type": "boolean"
                      },
                      "condition": {
                        "type": "string"
                      },
                      "triggerType": {
                        "enum": [
                          "referralTrigger"
                        ]
                      }
                    }
                  }
                ]
              }
            }
          },
          "performsConversion": {
            "enum": [
              false,
              true
            ],
            "type": "boolean",
            "title": "Should a referred user meeting this objective's condition convert the referral?",
            "enumNames": [
              "Don't convert referral",
              "Convert referral"
            ]
          },
          "referrerProgramRewardLimit": {
            "$ref": "#/definitions/rewardLimit"
          }
        }
      },
      "rewardTier": {
        "type": "object",
        "required": [
          "condition",
          "reward",
          "key"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9\\-_]*$"
          },
          "reward": {
            "$ref": "#/definitions/reward"
          },
          "condition": {
            "type": "string"
          },
          "overrideRewardKey": {
            "type": "string"
          }
        }
      },
      "rewardLimit": {
        "type": "object",
        "required": [
          "limitType"
        ],
        "properties": {
          "limitType": {
            "enum": [
              "unlimited",
              "limited"
            ],
            "type": "string",
            "enumNames": [
              "Unlimited rewards",
              "A fixed number of rewards"
            ]
          }
        },
        "dependencies": {
          "limitType": {
            "oneOf": [
              {
                "properties": {
                  "limitType": {
                    "enum": [
                      "unlimited"
                    ]
                  }
                }
              },
              {
                "required": [
                  "maxRewards"
                ],
                "properties": {
                  "limitType": {
                    "enum": [
                      "limited"
                    ]
                  },
                  "maxRewards": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "overrideEmailKey": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9\\-_]*$"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}