{
  "$schema": "https://json-schema.org/draft-07/schema",
  "title": "Payload Schema",
  "type": "object",
  "oneOf": [
    {
      "title": "Snapshot Event",
      "required": [
        "op",
        "after"
      ],
      "properties": {
        "op": {
          "description": "Change event generated by a snapshot procedure",
          "const": "r"
        },
        "after": {
          "type": "object",
          "additionalProperties": true,
          "description": "The value of the payload after the modification occurred"
        },
        "before": {
          "type": "null",
          "description": "The value of the payload before the modification occurred. For snapshot operations this is not available"
        },
        "source": {
          "$ref": "#/definitions/source"
        },
        "ts_ms": {
          "$ref": "#/definitions/workload_ts_ms"
        },
        "updateDescription": {
          "$ref": "#/definitions/updateDescription"
        }
      }
    },
    {
      "title": "Create Event",
      "required": [
        "op",
        "after"
      ],
      "properties": {
        "op": {
          "description": "Change event generated when a new record is created on the data source",
          "const": "c"
        },
        "after": {
          "type": "object",
          "additionalProperties": true,
          "description": "The value of the payload after the modification occurred"
        },
        "before": {
          "type": "null",
          "description": "The value of the payload before the modification occurred. For create operations this is not available"
        },
        "source": {
          "$ref": "#/definitions/source"
        },
        "ts_ms": {
          "$ref": "#/definitions/workload_ts_ms"
        },
        "updateDescription": {
          "$ref": "#/definitions/updateDescription"
        }
      }
    },
    {
      "title": "Update Event",
      "required": [
        "op",
        "after",
        "before"
      ],
      "properties": {
        "op": {
          "description": "Change event generated when an existing record was modified on the data source",
          "const": "u"
        },
        "after": {
          "type": "object",
          "additionalProperties": true,
          "description": "The value of the payload after the modification occurred"
        },
        "before": {
          "type": "object",
          "additionalProperties": true,
          "description": "The value of the payload before the modification occurred"
        },
        "source": {
          "$ref": "#/definitions/source"
        },
        "ts_ms": {
          "$ref": "#/definitions/workload_ts_ms"
        },
        "updateDescription": {
          "$ref": "#/definitions/updateDescription"
        }
      }
    },
    {
      "title": "Delete Event",
      "required": [
        "op",
        "before"
      ],
      "properties": {
        "op": {
          "description": "Change event generated when an existing record was deleted from the data source",
          "const": "d"
        },
        "after": {
          "type": "null",
          "description": "The value of the payload after the modification occurred. For delete operations this is not available"
        },
        "before": {
          "type": "object",
          "additionalProperties": true,
          "description": "The value of the payload before the modification occurred"
        },
        "source": {
          "$ref": "#/definitions/source"
        },
        "ts_ms": {
          "$ref": "#/definitions/workload_ts_ms"
        },
        "updateDescription": {
          "$ref": "#/definitions/updateDescription"
        }
      }
    }
  ],
  "definitions": {
    "source": {
      "type": "object",
      "properties": {
        "db": {
          "type": "string",
          "description": "Name of the database containing the original record"
        },
        "collection": {
          "type": "string",
          "description": "Name of the MongoDB collection containing the original record"
        },
        "table": {
          "type": "string",
          "description": "Name of the table containing the original record"
        },
        "ts_ms": {
          "$ref": "#/definitions/source_ts_ms"
        }
      },
      "additionalProperties": true,
      "description": "Metadata regarding the data source containing the original record this change event is associated to"
    },
    "source_ts_ms": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix timestamp in milliseconds representing when the record modification occurred on the data source"
    },
    "workload_ts_ms": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix timestamp in milliseconds representing when the change event was processed by the current workload"
    },
    "updateDescription": {
      "anyOf": [
        {
          "type": "object",
          "description": "Metadata describing how the record was modified",
          "properties": {
            "updatedFields": {
              "type": "object"
            },
            "removedFields": {
              "type": "object"
            },
            "truncated_arrays": {
              "anyOf": [
                {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "field": {
                        "type": "string"
                      },
                      "newSize": {
                        "type": "number",
                        "format": "int32"
                      }
                    }
                  }
                },
                {
                  "type": "null"
                }
              ]
            },
            "disambiguatedPaths": {
              "anyOf": [
                {
                  "type": "object"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ]
    }
  }
}
