{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "User Metric JSONata Context",
  "description": "Context provided to a custom user metric JSONata filter expression",
  "type": "object",
  "properties": {
    "user": {
      "title": "User Data",
      "type": "object",
      "properties": {
        "firstName": {
          "type": [
            "string",
            "null"
          ],
          "title": "First Name"
        },
        "lastName": {
          "type": [
            "string",
            "null"
          ],
          "title": "Last Name"
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "title": "Email Address"
        },
        "locale": {
          "type": [
            "string",
            "null"
          ],
          "title": "Locale"
        },
        "dateCreated": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Created"
        },
        "dateBlocked": {
          "type": [
            "integer",
            "null"
          ],
          "title": "Date User Blocked"
        },
        "segments": {
          "type": "array",
          "title": "Segments",
          "description": "A list of segments this user has been assigned to",
          "items": {
            "type": "string",
            "title": "Segment Key",
            "description": "A segment key this user has been assigned to (e.g. VIP)"
          }
        },
        "fraudFlags": {
          "type": "array",
          "title": "Fraud Flags",
          "description": "Flags indicating whether this user was marked as a potentially fradulent user",
          "items": {
            "type": "object",
            "title": "Fraud Flag",
            "properties": {
              "type": {
                "type": "string",
                "title": "Flag Type",
                "enum": [
                  "IP",
                  "EMAIL",
                  "NAME",
                  "RATE",
                  "DAILY_REFERRAL_REWARD_LIMIT",
                  "TEMP_EMAIL",
                  "BLOCKED_USER",
                  "BLOCKED_IP"
                ]
              },
              "message": {
                "type": "string",
                "title": "Flag Description"
              }
            },
            "required": [
              "type",
              "message"
            ],
            "additionalProperties": false
          }
        },
        "customFields": {
          "$ref": "#/definitions/customFieldsContext"
        }
      }
    },
    "event": {
      "$ref": "#/definitions/eventContext"
    }
  },
  "definitions": {
    "eventContext": {
      "type": "object",
      "title": "Event",
      "description": "The variables for the event that triggered the metric",
      "properties": {
        "key": {
          "type": "string",
          "title": "Event Key",
          "description": "The key of the evaluated event (e.g. purchase)"
        },
        "dateTriggered": {
          "type": "integer",
          "title": "Date Triggered",
          "description": "The date this event was created"
        },
        "fields": {
          "$ref": "#/definitions/eventFieldsContext"
        }
      }
    },
    "eventFieldsContext": {
      "title": "Event Fields",
      "description": "The event's fields",
      "type": "object",
      "additionalProperties": true
    },
    "customFieldsContext": {
      "title": "User Custom Fields",
      "description": "The user's custom fields",
      "type": "object",
      "additionalProperties": true
    }
  }
}