{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://golfsga.com/sga-ois/schema/0.1/heartbeat.schema.json",
  "title": "SGA-OIS heartbeat",
  "description": "Application liveness (09 section 4). A device sends its own clock as device_t_ms; only the engine's heartbeat carries t_ms.",
  "oneOf": [
    {
      "$ref": "#/$defs/fromDevice"
    },
    {
      "$ref": "#/$defs/fromEngine"
    }
  ],
  "$defs": {
    "fromDevice": {
      "type": "object",
      "required": [
        "type"
      ],
      "additionalProperties": false,
      "properties": {
        "type": {
          "const": "session.heartbeat"
        },
        "device_t_ms": {
          "$ref": "common.schema.json#/$defs/deviceMs"
        },
        "ready": {
          "type": "boolean",
          "description": "The device can contribute to a stroke now."
        },
        "manifest_version": {
          "type": "integer",
          "minimum": 0,
          "description": "The manifest the device is working from."
        }
      },
      "patternProperties": {
        "^x-[a-z0-9_-]+\\.": {}
      }
    },
    "fromEngine": {
      "type": "object",
      "required": [
        "type",
        "t_ms",
        "session_epoch",
        "manifest_version"
      ],
      "additionalProperties": false,
      "properties": {
        "type": {
          "const": "session.heartbeat"
        },
        "t_ms": {
          "$ref": "common.schema.json#/$defs/monotonicMs"
        },
        "session_epoch": {
          "$ref": "common.schema.json#/$defs/sessionEpoch"
        },
        "manifest_version": {
          "type": "integer",
          "minimum": 0,
          "description": "The manifest in force, so a participant that missed one finds out within a second."
        }
      },
      "patternProperties": {
        "^x-[a-z0-9_-]+\\.": {}
      }
    }
  }
}
