{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://hybrid-arena.com/integrations/games/provider-v1/schemas.json",
  "title": "Arena game provider v1 (local reference)",
  "$defs": {
    "Outcome": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "outcome_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        }
      },
      "required": [
        "outcome_id",
        "label"
      ]
    },
    "Participant": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "actor_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "outcome_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        }
      },
      "required": [
        "actor_id",
        "outcome_id"
      ]
    },
    "Score": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "outcome_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "score": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "outcome_id",
        "score"
      ]
    },
    "GameManifest": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "arena.game.manifest.v1"
        },
        "publisher_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-z0-9.-]+)?$",
          "maxLength": 64
        },
        "ruleset_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "ruleset_version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-z0-9.-]+)?$",
          "maxLength": 64
        },
        "outcomes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Outcome"
          },
          "minItems": 2,
          "maxItems": 16
        },
        "capabilities": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "spectate": {
              "type": "boolean"
            },
            "join": {
              "type": "boolean"
            },
            "replays": {
              "type": "boolean"
            }
          },
          "required": [
            "spectate",
            "join",
            "replays"
          ]
        },
        "clock": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "kind": {
              "enum": [
                "simulation",
                "server"
              ]
            },
            "precision_ms": {
              "type": "integer",
              "minimum": 1,
              "maximum": 60000
            },
            "tick_rate_hz": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          },
          "required": [
            "kind",
            "precision_ms"
          ]
        }
      },
      "required": [
        "schema",
        "publisher_id",
        "game_id",
        "game_version",
        "ruleset_id",
        "ruleset_version",
        "outcomes",
        "capabilities",
        "clock"
      ]
    },
    "MatchRequest": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "arena.game.match.v1"
        },
        "publisher_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-z0-9.-]+)?$",
          "maxLength": 64
        },
        "ruleset_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "ruleset_version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[a-z0-9.-]+)?$",
          "maxLength": 64
        },
        "request_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "match_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "epoch": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "participants": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Participant"
          },
          "minItems": 0,
          "maxItems": 64
        },
        "activity": {
          "enum": [
            "synthetic",
            "bot",
            "human",
            "mixed",
            "not_reported"
          ]
        }
      },
      "required": [
        "schema",
        "publisher_id",
        "game_id",
        "game_version",
        "ruleset_id",
        "ruleset_version",
        "request_id",
        "match_id",
        "epoch",
        "participants"
      ]
    },
    "Event": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "match_started"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "type": "object",
              "additionalProperties": false,
              "properties": {},
              "required": []
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "score_changed"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "$ref": "#/$defs/Score"
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "game_event"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]*\\.[a-z][a-z0-9_.-]*$",
                  "maxLength": 96
                },
                "actor_id": {
                  "type": "string",
                  "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
                },
                "target_actor_id": {
                  "type": "string",
                  "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
                },
                "values": {
                  "type": "object",
                  "maxProperties": 32,
                  "propertyNames": {
                    "pattern": "^[a-z][a-z0-9_]{0,47}$"
                  },
                  "additionalProperties": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "boolean"
                      }
                    ]
                  }
                }
              },
              "required": [
                "name",
                "values"
              ]
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "match_completed"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "winner": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "scores": {
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/Score"
                  },
                  "minItems": 2,
                  "maxItems": 16
                }
              },
              "required": [
                "winner",
                "scores"
              ]
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "match_canceled"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "reason": {
                  "enum": [
                    "operator_canceled",
                    "source_unavailable",
                    "invalid_match"
                  ]
                }
              },
              "required": [
                "reason"
              ]
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "event_id": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "sequence": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "type": {
              "const": "source_gap"
            },
            "game_time_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "source_tick": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "occurred_at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
              "maxLength": 40
            },
            "payload": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "reason": {
                  "enum": [
                    "missing_events",
                    "source_restart",
                    "integrity_failure"
                  ]
                }
              },
              "required": [
                "reason"
              ]
            }
          },
          "required": [
            "event_id",
            "sequence",
            "type",
            "game_time_ms",
            "payload"
          ]
        }
      ]
    },
    "EventBatch": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "arena.game.events.v1"
        },
        "publisher_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "batch_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "match_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "epoch": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "first_sequence": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "previous_batch_sha256": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Event"
          },
          "minItems": 1,
          "maxItems": 100
        }
      },
      "required": [
        "schema",
        "publisher_id",
        "game_id",
        "batch_id",
        "match_id",
        "epoch",
        "first_sequence",
        "previous_batch_sha256",
        "events"
      ]
    },
    "Receipt": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "arena.game.receipt.v1"
        },
        "request_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "kind": {
          "enum": [
            "match.created",
            "events.accepted"
          ]
        },
        "publisher_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "game_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
        },
        "match_id": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "epoch": {
          "type": "string",
          "pattern": "^[a-f0-9]{32}$"
        },
        "request_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "manifest_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "first_sequence": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "last_sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "state": {
          "enum": [
            "created",
            "live",
            "held",
            "completed",
            "canceled"
          ]
        },
        "accepted_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?Z$",
          "maxLength": 40
        },
        "assurance": {
          "enum": [
            "local_reference_only",
            "arena_hosted_sandbox"
          ]
        },
        "anchor": {
          "type": "null"
        },
        "payout_authorized": {
          "const": false
        }
      },
      "required": [
        "schema",
        "request_id",
        "kind",
        "publisher_id",
        "game_id",
        "match_id",
        "epoch",
        "request_sha256",
        "manifest_sha256",
        "first_sequence",
        "last_sequence",
        "state",
        "accepted_at",
        "assurance",
        "anchor",
        "payout_authorized"
      ]
    },
    "Error": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "error": {
          "type": "string",
          "pattern": "^[a-z_]+$"
        },
        "expected_sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "error"
      ]
    }
  }
}
