{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Matchfeed v1 football data envelope",
  "type": "object",
  "required": [
    "type",
    "match_id",
    "feed",
    "cursor",
    "received_at",
    "data"
  ],
  "properties": {
    "type": {
      "enum": [
        "snapshot",
        "update",
        "gap"
      ]
    },
    "match_id": {
      "type": "string",
      "pattern": "^mf_[0-9a-f]{20}$"
    },
    "feed": {
      "enum": [
        "A",
        "B",
        "C"
      ]
    },
    "cursor": {
      "type": "string",
      "minLength": 1
    },
    "received_at": {
      "type": "string",
      "format": "date-time"
    },
    "data": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "additionalProperties": true,
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "gap"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "required": [
              "reason"
            ],
            "properties": {
              "reason": {
                "enum": [
                  "invalid_transfer",
                  "source_reconnect"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "snapshot"
          },
          "feed": {
            "const": "C"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "required": [
              "revision",
              "events"
            ],
            "properties": {
              "events": {
                "type": "array"
              },
              "revision": {
                "anyOf": [
                  {
                    "type": "integer"
                  },
                  {
                    "type": "string",
                    "pattern": "^-?[0-9]+$"
                  }
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "update"
          },
          "feed": {
            "const": "C"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "required": [
              "mode",
              "revision",
              "state"
            ],
            "properties": {
              "mode": {
                "enum": [
                  "state",
                  "patch"
                ]
              },
              "revision": {
                "anyOf": [
                  {
                    "type": "integer"
                  },
                  {
                    "type": "string",
                    "pattern": "^-?[0-9]+$"
                  }
                ]
              },
              "state": {
                "type": "object"
              }
            },
            "if": {
              "properties": {
                "mode": {
                  "const": "patch"
                }
              }
            },
            "then": {
              "required": [
                "events",
                "event_ids"
              ],
              "oneOf": [
                {
                  "required": [
                    "event_order"
                  ]
                },
                {
                  "required": [
                    "order_new"
                  ]
                }
              ]
            }
          }
        }
      }
    }
  ]
}
