{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "Program Request",
  "description": "The requests that will be sent from the backend to the program",
  "type": "object",
  "properties": {
    "messageType": {
      "type": "string",
      "title": "Message Type",
      "description": "The type of request being made to the program",
      "enum": [
        "PROGRAM_TRIGGER",
        "PROGRAM_VALIDATION",
        "PROGRAM_INTROSPECTION",
        "PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST"
      ]
    },
    "version": {
      "type": "string",
      "title": "RPC Version",
      "description": "The RPC version for this program request"
    }
  },
  "dependencies": {
    "messageType": {
      "oneOf": [
        {
          "$ref": "#/definitions/programTrigger"
        },
        {
          "$ref": "#/definitions/programValidation"
        },
        {
          "$ref": "#/definitions/programIntrospection"
        },
        {
          "$ref": "#/definitions/programTriggerVariablesSchemaRequest"
        }
      ]
    }
  },
  "definitions": {
    "programTrigger": {
      "type": "object",
      "title": "Program Trigger",
      "description": "A request for the program to evaluate a user for against its criteria (determines whether to reward/email/etc. the user)",
      "properties": {
        "messageType": {
          "enum": [
            "PROGRAM_TRIGGER"
          ]
        }
      },
      "additionalProperties": true
    },
    "programValidation": {
      "type": "object",
      "title": "Program Validation",
      "description": "A request for the program to validate requirement query results",
      "properties": {
        "messageType": {
          "enum": [
            "PROGRAM_VALIDATION"
          ]
        },
        "validationRequests": {
          "type": "array",
          "title": "Validation Requests",
          "description": "The validations we're asking the program to perform for a given set of requirement keys and associated query results",
          "items": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string",
                "title": "Requirement Key",
                "description": "The requirement key we're validating"
              },
              "queryResult": {
                "type": "object",
                "title": "Query Result",
                "description": "The requests from running the query associated with this requirement key"
              }
            },
            "additionalProperties": false
          }
        }
      }
    },
    "programIntrospection": {
      "type": "object",
      "title": "Program Introspection",
      "description": "A request for the program to alter its template according to the provided program rules",
      "properties": {
        "messageType": {
          "enum": [
            "PROGRAM_INTROSPECTION"
          ]
        },
        "template": {
          "$schema": "http://json-schema.org/draft-06/schema#",
          "title": "Program Template Builder",
          "description": "Build your program using the magic of magic!",
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "title": "ID",
              "description": "The unique contentful ID associated with this program template"
            },
            "name": {
              "type": "string",
              "title": "Program Name",
              "description": "A human-readable name for the program. Dispayed in the SaaSquatch Portal during Program setup."
            },
            "summary": {
              "type": "string",
              "title": "Program Summary",
              "description": "A human-readable summary of the program. Dispayed in the SaaSquatch Portal during Program setup."
            },
            "longDescription": {
              "type": "string",
              "options": {
                "expand_height": true
              },
              "title": "Program Long Description",
              "description": "A long-form article that sells the benefits of this program. Dispayed in the SaaSquatch Portal during Program setup."
            },
            "installGuide": {
              "type": "string",
              "title": "Program Install Guide",
              "description": "This describes how to setup the current program and may update depending on how you've configured your program rules"
            },
            "rewards": {
              "type": "array",
              "title": "Rewards",
              "description": "A list of all the possible types of rewards this program will give. Your business logic will trigger these based on key",
              "items": {
                "headerTemplate": "{{ self.name }}",
                "$ref": "#/definitions/programIntrospection/properties/template/definitions/RewardType"
              }
            },
            "emails": {
              "type": "array",
              "title": "Emails",
              "description": "A list of all the possible types of emails this program will send. Your business logic will trigger these based on key",
              "items": {
                "headerTemplate": "{{ self.name }}",
                "$ref": "#/definitions/programIntrospection/properties/template/definitions/EmailType"
              }
            },
            "logo": {
              "type": "string",
              "title": "Logo URL",
              "description": "The URL for the logo associated with this program"
            },
            "widgets": {
              "type": "array",
              "title": "Widgets",
              "description": "A list of all the possible types of widgets this program will send. Your business logic will trigger these based on key",
              "items": {
                "$ref": "#/definitions/programIntrospection/properties/template/definitions/EmailType"
              }
            },
            "globallyInstallable": {
              "type": "boolean",
              "title": "Globally Installable",
              "description": "Indicates whether this program can be installed by any tenant that support GA"
            },
            "installableByTenants": {
              "type": [
                "array",
                "null"
              ],
              "title": "Installable by Tenants",
              "description": "The tenants that can install this program if it's not globally installable",
              "items": {
                "type": "string",
                "title": "Tenant Alias",
                "description": "The tenant alias for a tenant that can install this program"
              }
            },
            "rules": {
              "title": "Business Rule Variables",
              "description": "The business rule variables define a JSON schema of the possible configuration points in the business logic.",
              "type": "object",
              "options": {
                "hidden": true
              }
            },
            "sharing": {
              "type": [
                "object",
                "null"
              ],
              "title": "Sharing",
              "properties": {
                "enabled": {
                  "type": "boolean",
                  "title": "Sharing Enabled",
                  "description": "When sharing is enabled the program will create/support referral share links"
                },
                "linksConfig": {
                  "type": "object",
                  "title": "Links Configuration",
                  "description": "Message links configuration (default share text/content for Open Graph/Twitter/etc)",
                  "properties": {
                    "defaults": {
                      "$schema": "http://json-schema.org/draft-06/schema#",
                      "title": "Program Messaging",
                      "description": "Defines the configurable share messages provided by this program.",
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "shareLinkOpenGraph",
                        "messageLinkOpenGraph",
                        "messages"
                      ],
                      "properties": {
                        "shareLinkOpenGraph": {
                          "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/openGraph"
                        },
                        "messageLinkOpenGraph": {
                          "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/openGraph"
                        },
                        "messages": {
                          "type": "array",
                          "title": "Share Messages",
                          "items": [
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/twitter"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/email"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/linkedin"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/sms"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/whatsapp"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/linemessenger"
                            },
                            {
                              "$ref": "#/definitions/programIntrospection/properties/template/properties/sharing/properties/linksConfig/properties/defaults/definitions/pinterest"
                            }
                          ],
                          "additionalItems": false,
                          "minItems": 7,
                          "maxItems": 7
                        }
                      },
                      "definitions": {
                        "openGraph": {
                          "type": "object",
                          "title": "Share Link Open Graph",
                          "properties": {
                            "source": {
                              "type": "string",
                              "enum": [
                                "HOSTED",
                                "LANDING_PAGE"
                              ],
                              "enumNames": [
                                "Hosted",
                                "Landing Page"
                              ],
                              "default": "LANDING_PAGE"
                            }
                          },
                          "dependencies": {
                            "source": {
                              "oneOf": [
                                {
                                  "properties": {
                                    "source": {
                                      "enum": [
                                        "HOSTED"
                                      ]
                                    },
                                    "title": {
                                      "type": "string",
                                      "title": "Title",
                                      "minLength": 4
                                    },
                                    "description": {
                                      "type": "string",
                                      "title": "Description",
                                      "minLength": 4
                                    },
                                    "image": {
                                      "type": "string",
                                      "title": "Image"
                                    }
                                  },
                                  "additionalProperties": false,
                                  "required": [
                                    "source",
                                    "title",
                                    "description"
                                  ]
                                },
                                {
                                  "properties": {
                                    "source": {
                                      "enum": [
                                        "LANDING_PAGE"
                                      ]
                                    }
                                  },
                                  "additionalProperties": false,
                                  "required": [
                                    "source"
                                  ]
                                }
                              ]
                            }
                          }
                        },
                        "twitter": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "TWITTER",
                              "enum": [
                                "TWITTER"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "X",
                              "properties": {
                                "twitterShareBody": {
                                  "type": "string",
                                  "title": "X Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "twitterShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "email": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "EMAIL",
                              "enum": [
                                "EMAIL"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "Email",
                              "properties": {
                                "emailShareSubject": {
                                  "type": "string",
                                  "title": "Email Share Subject",
                                  "minLength": 4
                                },
                                "emailShareBody": {
                                  "type": "string",
                                  "title": "Email Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "emailShareSubject",
                                "emailShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "linkedin": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "LINKEDIN",
                              "enum": [
                                "LINKEDIN"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "LinkedIn",
                              "properties": {
                                "linkedinShareSubject": {
                                  "type": "string",
                                  "title": "LinkedIn Share Subject",
                                  "minLength": 4
                                },
                                "linkedinShareBody": {
                                  "type": "string",
                                  "title": "LinkedIn Share Body",
                                  "minLength": 4
                                },
                                "linkedinShareImageURL": {
                                  "type": "string",
                                  "title": "LinkedIn URL Image"
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "linkedinShareSubject",
                                "linkedinShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "sms": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "SMS",
                              "enum": [
                                "SMS"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "SMS",
                              "properties": {
                                "smsShareBody": {
                                  "type": "string",
                                  "title": "SMS Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "smsShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "whatsapp": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "WHATSAPP",
                              "enum": [
                                "WHATSAPP"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "WhatsApp",
                              "properties": {
                                "whatsAppShareBody": {
                                  "type": "string",
                                  "title": "WhatsApp Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "whatsAppShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "linemessenger": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "LINEMESSENGER",
                              "enum": [
                                "LINEMESSENGER"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "Line Messenger",
                              "properties": {
                                "lineMessengerShareBody": {
                                  "type": "string",
                                  "title": "Line Messenger Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false,
                              "required": [
                                "lineMessengerShareBody"
                              ]
                            }
                          },
                          "additionalProperties": false
                        },
                        "pinterest": {
                          "type": "object",
                          "properties": {
                            "shareMedium": {
                              "type": "string",
                              "default": "PINTEREST",
                              "enum": [
                                "PINTEREST"
                              ]
                            },
                            "config": {
                              "type": "object",
                              "title": "Pinterest",
                              "properties": {
                                "pinterestImageURL": {
                                  "type": "string",
                                  "title": "Pinterest Image URL"
                                },
                                "pinterestShareBody": {
                                  "type": "string",
                                  "title": "Pinterest Share Body",
                                  "minLength": 4
                                }
                              },
                              "additionalProperties": false
                            }
                          },
                          "additionalProperties": false
                        }
                      }
                    }
                  }
                }
              }
            },
            "schedule": {
              "title": "Recurring schedule",
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "userFilter": {
                  "type": "object",
                  "title": "User Filter",
                  "description": "This should be a GraphQL-compatible query json object"
                },
                "periodInHours": {
                  "type": "number",
                  "description": "Your program logic will be run on this schedule."
                }
              }
            },
            "schedules": {
              "type": [
                "array",
                "null"
              ],
              "title": "Program Schedules",
              "description": "The backend schedules that will run at a specified interval and trigger the program for specified users",
              "items": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "title": "Schedule Type",
                    "description": "The type of schedule to run",
                    "enum": [
                      "USER",
                      "REWARD"
                    ]
                  },
                  "key": {
                    "type": "string",
                    "title": "Schedule Key",
                    "description": "A unique identifier for this specific schedule"
                  },
                  "periodInHours": {
                    "type": "integer",
                    "title": "Period in Hours",
                    "description": "The interval by which this schedule will run (e.g. every x hours)"
                  },
                  "filter": {
                    "type": "object",
                    "title": "Filter",
                    "description": "The filter used to determine which users are evaluated when the schedule is run"
                  },
                  "query": {
                    "type": "string",
                    "title": "Query",
                    "description": "The query used to create the program context when a user is evaluated by the schedule"
                  }
                }
              }
            },
            "settings": {
              "type": "object",
              "properties": {
                "referrals": {
                  "type": "object",
                  "properties": {
                    "enabled": {
                      "type": "boolean",
                      "description": "Whether this program supports referrals"
                    }
                  }
                }
              }
            },
            "rulesUISchema": {
              "type": "object",
              "title": "Rules UI Schema",
              "description": "Defines how the rules will be shown via schema form"
            },
            "requirements": {
              "type": [
                "array",
                "null"
              ],
              "title": "Program Requirements",
              "description": "All of these conditions should be satisfied to confirm the program is working",
              "items": {
                "$ref": "#/definitions/programIntrospection/properties/template/definitions/Requirement"
              }
            },
            "userMetrics": {
              "type": "array",
              "title": "Program User Metrics",
              "description": "Custom metrics defined by this program that will only be activated when the program is live",
              "items": {
                "$schema": "http://json-schema.org/draft-06/schema#",
                "title": "User Metric",
                "description": "User metrics establish how aggregate functions can be used to update a custom user field with respect to an event.",
                "type": "object",
                "properties": {
                  "customFieldKey": {
                    "type": "string",
                    "title": "Custom Field",
                    "description": "The name of the custom field associated with this metric. "
                  },
                  "aggregateId": {
                    "type": "string",
                    "title": "Aggregate Identifier",
                    "description": "An unique identifier for the aggregate operation to perform.",
                    "enum": [
                      "SUM",
                      "COUNT",
                      "FIRST_SEEN",
                      "LAST_SEEN",
                      "FIRST_VALUE",
                      "LAST_VALUE",
                      "THROTTLED_LAST_NUMERIC_VALUE"
                    ]
                  },
                  "dateTriggeredWindow": {
                    "type": "string",
                    "title": "Date Triggered Window",
                    "description": "An ISO 8601 interval. The aggregate operation will only be performed between this window."
                  },
                  "userEventKey": {
                    "type": "string",
                    "title": "User Event Key",
                    "description": "The event that will be aggregated by this metric."
                  },
                  "filter": {
                    "type": "string",
                    "title": "Filter",
                    "description": "A JSONata expression which will filter out non-matching events"
                  }
                },
                "required": [
                  "customFieldKey",
                  "aggregateId",
                  "userEventKey"
                ],
                "dependencies": {
                  "aggregateId": {
                    "oneOf": [
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "SUM"
                            ]
                          },
                          "aggregateRules": {
                            "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/singleFieldWithWindowingAggregate"
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "COUNT"
                            ]
                          },
                          "aggregateRules": {
                            "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/windowingAggregate"
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "FIRST_SEEN"
                            ]
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "LAST_SEEN"
                            ]
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "FIRST_VALUE"
                            ]
                          },
                          "aggregateRules": {
                            "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/singleFieldAggregate"
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "LAST_VALUE"
                            ]
                          },
                          "aggregateRules": {
                            "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/singleFieldAggregate"
                          }
                        }
                      },
                      {
                        "properties": {
                          "aggregateId": {
                            "enum": [
                              "THROTTLED_LAST_NUMERIC_VALUE"
                            ]
                          },
                          "aggregateRules": {
                            "type": "object",
                            "properties": {
                              "fieldName": {
                                "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/fieldName"
                              },
                              "diff": {
                                "type": "string",
                                "title": "Throttle Interval",
                                "description": "The minimum interval time that can elapse between recording the value of field name. Default is milliseconds per hour."
                              }
                            },
                            "additionalProperties": false,
                            "required": [
                              "fieldName"
                            ]
                          }
                        }
                      }
                    ]
                  }
                },
                "definitions": {
                  "singleFieldAggregate": {
                    "type": "object",
                    "properties": {
                      "fieldName": {
                        "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/fieldName"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "fieldName"
                    ]
                  },
                  "singleFieldWithWindowingAggregate": {
                    "type": "object",
                    "properties": {
                      "fieldName": {
                        "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/fieldName"
                      },
                      "windowing": {
                        "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/windowing"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "fieldName"
                    ]
                  },
                  "windowingAggregate": {
                    "type": "object",
                    "properties": {
                      "windowing": {
                        "$ref": "#/definitions/programIntrospection/properties/template/properties/userMetrics/items/definitions/windowing"
                      }
                    },
                    "additionalProperties": false
                  },
                  "fieldName": {
                    "type": "string",
                    "title": "Field Name",
                    "description": "The field on which this aggregate will be performed."
                  },
                  "windowing": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "FIXED",
                          "SLIDING"
                        ]
                      }
                    },
                    "required": [
                      "type"
                    ],
                    "dependencies": {
                      "type": {
                        "oneOf": [
                          {
                            "properties": {
                              "type": {
                                "enum": [
                                  "FIXED"
                                ]
                              },
                              "unit": {
                                "type": "string",
                                "enum": [
                                  "DAY",
                                  "WEEK",
                                  "MONTH",
                                  "YEAR"
                                ]
                              }
                            },
                            "required": [
                              "type",
                              "unit"
                            ]
                          },
                          {
                            "properties": {
                              "type": {
                                "enum": [
                                  "SLIDING"
                                ]
                              },
                              "duration": {
                                "type": "integer",
                                "minimum": 1,
                                "maximum": 90
                              },
                              "unit": {
                                "type": "string",
                                "enum": [
                                  "DAY",
                                  "WEEK",
                                  "MONTH",
                                  "YEAR"
                                ]
                              },
                              "maxBucketValue": {
                                "type": "number"
                              }
                            },
                            "required": [
                              "type",
                              "duration",
                              "unit"
                            ]
                          }
                        ]
                      }
                    }
                  }
                }
              }
            },
            "url": {
              "type": "string",
              "title": "Webtask URL",
              "description": "The URL that will be requested for this program when triggered"
            },
            "trigger": {
              "type": "object",
              "title": "Program Triggers",
              "description": "Defines specific triggers for this program",
              "properties": {
                "eventKeys": {
                  "type": "array",
                  "title": "Event Keys",
                  "description": "A list of events that can trigger this program",
                  "items": {
                    "type": "string",
                    "title": "Event Key",
                    "description": "When an event with this key is received this program will be triggered. Deprecated in favour of userEventKeys."
                  }
                },
                "userEventKeys": {
                  "type": "array",
                  "title": "User Event Keys",
                  "description": "A list of events that can trigger this program",
                  "items": {
                    "type": "string",
                    "title": "User Event Key",
                    "description": "When an event with this key is received this program will be triggered"
                  }
                },
                "customFieldKeys": {
                  "type": "array",
                  "title": "Custom Field Keys",
                  "description": "A list of custom field keys that this program evaluates on",
                  "items": {
                    "type": "string",
                    "title": "Custom Field Key",
                    "description": "When a custom field with this key is received this program may perform mutations"
                  }
                }
              }
            },
            "rulesMigrationScript": {
              "type": "string",
              "title": "Rules Migration Script",
              "description": "A JSONata script that transforms program rules JSON to be compatible with the most recently published schema version"
            },
            "goals": {
              "type": "array",
              "title": "Goals",
              "description": "Template of program goals provided by this program",
              "items": {
                "type": "object",
                "properties": {
                  "goalId": {
                    "type": "string",
                    "title": "Goal ID",
                    "description": "The program goal ID"
                  },
                  "name": {
                    "type": "string",
                    "title": "Name",
                    "description": "The human readable name"
                  }
                },
                "required": [
                  "goalId"
                ],
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false,
          "definitions": {
            "EmailType": {
              "title": "Email Type",
              "description": "A type of email that is given by this program.",
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "title": "Key",
                  "description": "A unique key to identify this email type. Only numbers and latin characers are allowed. Email types must be unique within the scope of a program. e.g. `RewardCreatedEmail`",
                  "pattern": "[a-zA-Z0-9]+",
                  "default": "rewardCreatedEmail"
                },
                "name": {
                  "type": "string",
                  "title": "Name",
                  "description": "A human-readable name for the email type that gets displayed in the SaaSquatch portal during program setup. e.g. `Reward Created Email`",
                  "default": "Reward Created Email"
                },
                "description": {
                  "type": "string",
                  "title": "Description",
                  "description": "A human-readable description that explains this email type. Displayed in the SaaSquatch portal during program setup. e.g. `This email is sent when a new reward is created by this program`",
                  "default": "We send this email when a new reward is created by this program"
                },
                "defaults": {
                  "oneOf": [
                    {
                      "type": "string",
                      "title": "Default Template Id"
                    },
                    {
                      "$schema": "http://json-schema.org/draft-06/schema#",
                      "title": "Simple Email Template Schema",
                      "description": "Defines the customization points available in a Simple Email Template.",
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "meta",
                        "content"
                      ],
                      "properties": {
                        "meta": {
                          "type": "object",
                          "title": "Email",
                          "required": [
                            "fromName",
                            "fromAddress",
                            "subject"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "fromName": {
                              "type": "string",
                              "title": "From Name",
                              "default": "My Company",
                              "propertyOrder": 1,
                              "minLength": 1,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ]
                              }
                            },
                            "fromAddress": {
                              "type": "string",
                              "title": "From Address",
                              "default": "company@example.com",
                              "propertyOrder": 2,
                              "minLength": 5,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ]
                              }
                            },
                            "subject": {
                              "type": "string",
                              "title": "Subject",
                              "propertyOrder": 3,
                              "minLength": 1,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ],
                                "input_height": "50px"
                              }
                            }
                          }
                        },
                        "content": {
                          "type": "object",
                          "title": "Content",
                          "required": [
                            "bodyContent"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "headerImage": {
                              "title": "Header Image",
                              "type": "string"
                            },
                            "headerContent": {
                              "title": "Header",
                              "type": "string",
                              "options": {
                                "validate": [
                                  "handlebars"
                                ],
                                "input_height": "50px"
                              }
                            },
                            "bodyContent": {
                              "title": "Body",
                              "type": "string",
                              "description": "Supports markdown and handlebars expressions. e.g. *bold* _underline_ and [link](https://example.com)",
                              "options": {
                                "validate": [
                                  "handlebars"
                                ]
                              }
                            },
                            "cta": {
                              "type": "object",
                              "title": "Call to Action",
                              "properties": {
                                "enabled": {
                                  "title": "Display CTA button?",
                                  "type": "boolean",
                                  "default": false
                                },
                                "text": {
                                  "title": "Text",
                                  "type": "string"
                                },
                                "link": {
                                  "title": "Link",
                                  "type": "string"
                                }
                              }
                            },
                            "footerContent": {
                              "title": "Footer",
                              "type": "string",
                              "options": {
                                "validate": [
                                  "handlebars"
                                ],
                                "input_height": "50px"
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "$schema": "http://json-schema.org/draft-06/schema",
                      "title": "HTML Email Template Schema",
                      "description": "Defines the customization points available in an HTML body email template.",
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "meta",
                        "htmlContent"
                      ],
                      "properties": {
                        "meta": {
                          "type": "object",
                          "title": "Email",
                          "required": [
                            "fromName",
                            "fromAddress",
                            "subject"
                          ],
                          "additionalProperties": false,
                          "properties": {
                            "fromName": {
                              "type": "string",
                              "title": "From Name",
                              "default": "My Company",
                              "propertyOrder": 1,
                              "minLength": 1,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ]
                              }
                            },
                            "fromAddress": {
                              "type": "string",
                              "title": "From Address",
                              "default": "company@example.com",
                              "propertyOrder": 2,
                              "minLength": 5,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ]
                              }
                            },
                            "subject": {
                              "type": "string",
                              "title": "Subject",
                              "propertyOrder": 3,
                              "minLength": 1,
                              "options": {
                                "validate": [
                                  "handlebars"
                                ],
                                "input_height": "50px"
                              }
                            },
                            "bcc": {
                              "type": "array",
                              "title": "BCC",
                              "items": {
                                "type": "string",
                                "minLength": 5
                              }
                            }
                          }
                        },
                        "htmlContent": {
                          "type": "string",
                          "title": "HTML Content",
                          "description": "Raw HTML content that can use {{mergeTags}} from handlebars"
                        },
                        "jsonContent": {
                          "type": "object",
                          "title": "JSON Content",
                          "description": "The JSON content for the email editor"
                        }
                      }
                    }
                  ]
                }
              }
            },
            "WidgetType": {
              "title": "Widget Type",
              "description": "A type of widget that is displayed by this program.",
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "title": "Key",
                  "description": "A unique key to identify this widget type. Only numbers and latin characers are allowed. Widget types must be unique within the scope of a program. e.g. `ReferrerWidget`",
                  "pattern": "[a-zA-Z0-9]+"
                },
                "name": {
                  "type": "string",
                  "title": "Name",
                  "description": "A human-readable name for the widget type that gets displayed in the SaaSquatch portal during program setup. e.g. `Referrer Widget`"
                },
                "description": {
                  "type": "string",
                  "title": "Description",
                  "description": "A human-readable description that explains this widget type. Displayed in the SaaSquatch portal during program setup. e.g. `This widget is sent when a new reward is created by this program`",
                  "default": "We send this widget when a new reward is created by this program"
                },
                "defaults": {
                  "$schema": "http://json-schema.org/draft-06/schema#",
                  "title": "HTML Widget Template Schema",
                  "description": "Defines a web-component based widget template that uses vanilla HTML.",
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "htmlTemplate"
                  ],
                  "properties": {
                    "meta": {
                      "type": "object",
                      "title": "Template Meta",
                      "additionalProperties": false,
                      "properties": {
                        "dependencies": {
                          "type": "array",
                          "description": "A list of NPM resources to load into the widget",
                          "items": {
                            "$ref": "#/definitions/programIntrospection/properties/template/definitions/WidgetType/properties/defaults/definitions/npmDependency"
                          }
                        },
                        "plugins": {
                          "type": "array",
                          "description": "A list of component editors used in editing the widget",
                          "items": {
                            "$ref": "#/definitions/programIntrospection/properties/template/definitions/WidgetType/properties/defaults/definitions/npmDependency"
                          }
                        }
                      }
                    },
                    "htmlTemplate": {
                      "type": "string",
                      "title": "HTML Template",
                      "description": "Raw HTML content that can use web components."
                    },
                    "autoPopup": {
                      "type": "boolean",
                      "title": "Auto Popup",
                      "description": "Whether this widget should automatically popup on page load",
                      "default": false
                    },
                    "brandingConfig": {
                      "type": "object",
                      "title": "Branding Config"
                    }
                  },
                  "definitions": {
                    "npmDependency": {
                      "type": "object",
                      "properties": {
                        "package": {
                          "type": "string",
                          "description": "An NPM package name or scoped package"
                        },
                        "version": {
                          "type": "string",
                          "description": "An NPM version string, such as Patch releases: 1.0 or 1.0.x or ~1.0.4 Minor releases: 1 or 1.x or ^1.0.4 Major releases: * or x",
                          "default": "latest"
                        },
                        "filePath": {
                          "type": "string",
                          "description": "The path to a resource in the specified package",
                          "default": ""
                        }
                      },
                      "required": [
                        "version",
                        "package"
                      ]
                    }
                  }
                }
              }
            },
            "RewardType": {
              "title": "Reward Type",
              "description": "A type of reward that is given by this program.",
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "title": "Key",
                  "description": "A unique key to identify this reward type. Only numbers and latin characers are allowed. Reward types must be unique within the scope of a program. e.g. `FirstPurchaseReward`",
                  "pattern": "[a-zA-Z0-9]+",
                  "default": "firstPurchaseReward"
                },
                "name": {
                  "type": "string",
                  "title": "Name",
                  "description": "A human-readable name for the reward type that gets displayed in the SaaSquatch portal during program setup. e.g. `First Purchase Reward`",
                  "default": "First Purchase Reward"
                },
                "description": {
                  "type": "string",
                  "title": "Description",
                  "description": "A human-readable description that explains this reward type. Displayed in the SaaSquatch portal during program setup. e.g. `This reward is given to people when they make their first purchase.`",
                  "default": "This reward is given to people when they make their first purchase."
                },
                "units": {
                  "type": "array",
                  "title": "Units",
                  "description": "A list of reward units this reward can potentially have",
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            "Requirement": {
              "title": "Program Requirement",
              "description": "A condition that should be satified to confirm this program is working",
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "title": "Key",
                  "description": "A unique identifier used to validate this requirement"
                },
                "name": {
                  "type": "string",
                  "title": "Name",
                  "description": "The human-friendly name of this requirement"
                },
                "description": {
                  "type": "string",
                  "title": "Description",
                  "description": "A description of how this requirement can be satisfied"
                },
                "longDescription": {
                  "type": "string",
                  "title": "Long Description",
                  "description": "Rich content regarding the implementation and other details relevant to this requirement"
                },
                "query": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "title": "GraphQL Query",
                  "description": "The results of this query will be used to validate this requirement has been satisfied"
                },
                "queryVariables": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "title": "GraphQL Query Variables",
                  "description": "These are passed in as parameters to the query"
                }
              },
              "required": [
                "key",
                "name",
                "description"
              ]
            }
          }
        },
        "rules": {
          "type": "object",
          "title": "Program Rules (deprecated)",
          "description": "The rules configured for this program"
        },
        "program": {
          "type": "object",
          "title": "Program",
          "properties": {
            "rules": {
              "type": "object",
              "title": "Program Rules",
              "description": "The rules configured for this program"
            },
            "id": {
              "type": "string",
              "title": "Program ID",
              "description": "The unique program ID"
            },
            "rewards": {
              "type": "array",
              "title": "Program Rewards",
              "description": "Rewards associated with this program",
              "items": {
                "$schema": "http://json-schema.org/draft-06/schema#",
                "title": "Pre-defined Rewards Schema",
                "description": "Establishes the available configuration for pre-defined.",
                "type": "object",
                "properties": {
                  "reward": {
                    "type": "object",
                    "title": "Predefiend Reward",
                    "properties": {
                      "rewardType": {
                        "type": "string",
                        "enum": [
                          "PCT_DISCOUNT",
                          "CREDIT",
                          "FUELTANK",
                          "INTEGRATION"
                        ]
                      },
                      "key": {
                        "type": "string",
                        "title": "Reward Key"
                      }
                    },
                    "required": [
                      "rewardType"
                    ],
                    "dependencies": {
                      "rewardType": {
                        "oneOf": [
                          {
                            "properties": {
                              "rewardType": {
                                "enum": [
                                  "PCT_DISCOUNT"
                                ]
                              },
                              "amount": {
                                "title": "Discount Percent",
                                "type": "integer"
                              },
                              "validityDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/validityDuration"
                              },
                              "pendingDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/pendingDuration"
                              }
                            },
                            "required": [
                              "amount"
                            ]
                          },
                          {
                            "properties": {
                              "rewardType": {
                                "enum": [
                                  "CREDIT"
                                ]
                              },
                              "amount": {
                                "title": "Credit Amount",
                                "type": "integer"
                              },
                              "unit": {
                                "type": "string",
                                "title": "Unit"
                              },
                              "validityDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/validityDuration"
                              },
                              "pendingDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/pendingDuration"
                              }
                            },
                            "required": [
                              "amount",
                              "unit"
                            ]
                          },
                          {
                            "properties": {
                              "rewardType": {
                                "enum": [
                                  "FUELTANK"
                                ]
                              },
                              "fuelTankType": {
                                "type": "string",
                                "title": "Reward Type",
                                "enum": [
                                  "PCT_DISCOUNT",
                                  "CREDIT"
                                ],
                                "enumNames": [
                                  "Discount",
                                  "Credit"
                                ]
                              },
                              "validityDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/validityDuration"
                              },
                              "pendingDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/pendingDuration"
                              }
                            },
                            "required": [
                              "fuelTankType"
                            ],
                            "dependencies": {
                              "fuelTankType": {
                                "oneOf": [
                                  {
                                    "properties": {
                                      "fuelTankType": {
                                        "enum": [
                                          "PCT_DISCOUNT"
                                        ]
                                      },
                                      "amount": {
                                        "title": "Discount Percent",
                                        "type": "integer"
                                      },
                                      "validityDuration": {
                                        "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/validityDuration"
                                      },
                                      "pendingDuration": {
                                        "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/pendingDuration"
                                      }
                                    },
                                    "required": [
                                      "amount"
                                    ]
                                  },
                                  {
                                    "properties": {
                                      "fuelTankType": {
                                        "enum": [
                                          "CREDIT"
                                        ]
                                      },
                                      "amount": {
                                        "title": "Credit Amount",
                                        "type": "integer"
                                      },
                                      "unit": {
                                        "type": "string",
                                        "title": "Unit"
                                      }
                                    },
                                    "required": [
                                      "amount",
                                      "unit"
                                    ]
                                  }
                                ]
                              }
                            }
                          },
                          {
                            "properties": {
                              "rewardType": {
                                "enum": [
                                  "INTEGRATION"
                                ]
                              },
                              "amount": {
                                "title": "Reward Amount",
                                "type": "integer"
                              },
                              "unit": {
                                "type": "string",
                                "title": "Gift Card Type"
                              },
                              "integrationId": {
                                "type": "string",
                                "title": "Integration Identifier"
                              },
                              "integrationSettings": {
                                "type": "object",
                                "title": "Integration Settings",
                                "properties": {
                                  "templateId": {
                                    "type": "string",
                                    "title": "Email Template ID"
                                  },
                                  "giftId": {
                                    "type": "string"
                                  },
                                  "utid": {
                                    "type": "string"
                                  }
                                }
                              },
                              "pendingDuration": {
                                "$ref": "#/definitions/programIntrospection/properties/program/properties/rewards/items/definitions/reward/definitions/pendingDuration"
                              }
                            },
                            "required": [
                              "amount"
                            ]
                          }
                        ]
                      }
                    }
                  }
                },
                "definitions": {
                  "reward": {
                    "definitions": {
                      "validityDuration": {
                        "type": "string",
                        "title": "Duration Reward Is Valid"
                      },
                      "pendingDuration": {
                        "type": "string",
                        "title": "Duration Reward Is Pending"
                      }
                    }
                  }
                }
              }
            }
          },
          "additionalProperties": false
        }
      }
    },
    "programTriggerVariablesSchemaRequest": {
      "type": "object",
      "title": "Program Trigger Variables Schema Request",
      "description": "A request for the programs trigger variables schema in case it is custom",
      "properties": {
        "messageType": {
          "enum": [
            "PROGRAM_TRIGGER_VARIABLES_SCHEMA_REQUEST"
          ]
        },
        "triggerType": {
          "type": "string",
          "enum": [
            "AFTER_USER_CREATED_OR_UPDATED",
            "SCHEDULED",
            "REWARD_SCHEDULED",
            "REFERRAL",
            "AFTER_USER_EVENT_PROCESSED"
          ]
        },
        "schema": {
          "type": "object",
          "title": "Default Schema",
          "description": "The default schema for the request, which will be overridden if necessary"
        }
      },
      "dependencies": {
        "triggerType": {
          "oneOf": [
            {
              "properties": {
                "triggerType": {
                  "enum": [
                    "SCHEDULED"
                  ]
                },
                "scheduleKey": {
                  "type": "string",
                  "title": "Schedule Key",
                  "description": "Will match on the user schedule variables schema we're requesting"
                }
              }
            },
            {
              "properties": {
                "triggerType": {
                  "type": "string",
                  "title": "Trigger Type",
                  "enum": [
                    "REWARD_SCHEDULED"
                  ]
                },
                "scheduleKey": {
                  "type": "string",
                  "title": "Schedule Key",
                  "description": "Will match on the reward schedule variables schema we're requesting"
                }
              }
            }
          ]
        }
      }
    }
  }
}