{
  "$id": "MatchRecord.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "Id.json"
    },
    "version": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991,
      "description": "Raised by the server on every change; clients send the version they last saw so conflicts can be spotted."
    },
    "updatedAt": {
      "$ref": "Timestamp.json"
    },
    "deletedAt": {
      "description": "Set when the record is deleted; deleted records are kept so other devices learn of the deletion.",
      "$ref": "Timestamp.json"
    },
    "matchId": {
      "description": "The planned match; absent for a quick match started on the watch, for which the server makes a match.",
      "$ref": "Id.json"
    },
    "device": {
      "description": "What recorded it, for example garmin:venu2.",
      "type": "string",
      "maxLength": 60
    },
    "outcome": {
      "type": "string",
      "enum": [
        "completed",
        "abandoned"
      ]
    },
    "periods": {
      "type": "array",
      "items": {
        "$ref": "PeriodPlayed.json"
      }
    },
    "score": {
      "type": "object",
      "properties": {
        "home": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "away": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "home",
        "away"
      ],
      "additionalProperties": false
    },
    "penalties": {
      "description": "Shoot-out score, when there was one.",
      "type": "object",
      "properties": {
        "home": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "away": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "home",
        "away"
      ],
      "additionalProperties": false
    },
    "distanceM": {
      "description": "Distance the referee covered during the match, in metres, from the watch's GPS.",
      "type": "number",
      "minimum": 0
    },
    "kickoffDirection": {
      "description": "Which way the first period's kickoff team attacked, when the referee recorded it on the watch (PRE-8); heatmaps use it (TRK-9).",
      "type": "object",
      "properties": {
        "team": {
          "type": "string",
          "enum": [
            "home",
            "away"
          ],
          "description": "The team that kicked off the first period."
        },
        "bearingDeg": {
          "type": "number",
          "minimum": 0,
          "exclusiveMaximum": 360,
          "description": "The compass bearing of the goal it attacked, in degrees from true north."
        }
      },
      "required": [
        "team",
        "bearingDeg"
      ],
      "additionalProperties": false
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "Event.json"
      }
    },
    "diagnostics": {
      "description": "How the recording went (DIAG-1).",
      "$ref": "MatchDiagnostics.json"
    }
  },
  "required": [
    "id",
    "version",
    "updatedAt",
    "outcome",
    "periods",
    "score",
    "events"
  ],
  "additionalProperties": false,
  "description": "What happened in a match, as recorded on a watch."
}
