{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "agent-heartbeat",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "protocol_version": {
      "const": 1
    },
    "agent_id": {
      "type": "string",
      "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "sent_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$"
    },
    "capabilities": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "php_https",
          "bound_ip",
          "openvpn",
          "wireguard",
          "http_connect",
          "socks5"
        ]
      }
    },
    "spool_pending": {
      "type": "integer",
      "minimum": 0
    },
    "spool_oldest_seconds": {
      "type": "integer",
      "minimum": 0
    },
    "disk_free_bytes": {
      "type": "integer",
      "minimum": 0
    },
    "clock_offset_ms": {
      "type": "integer"
    },
    "routes": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "route_version_id": {
            "type": "string",
            "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
          },
          "state": {
            "enum": [
              "healthy",
              "degraded",
              "unavailable",
              "quarantined"
            ]
          },
          "observed_public_ip": {
            "anyOf": [
              {
                "oneOf": [
                  {
                    "type": "string",
                    "format": "ipv4"
                  },
                  {
                    "type": "string",
                    "format": "ipv6"
                  }
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "verified_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time",
                "pattern": "Z$"
              },
              {
                "type": "null"
              }
            ]
          },
          "in_flight": {
            "type": "integer",
            "minimum": 0
          },
          "latency_ms": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          }
        },
        "required": [
          "route_version_id",
          "state",
          "observed_public_ip",
          "verified_at",
          "in_flight",
          "latency_ms"
        ]
      }
    }
  },
  "required": [
    "protocol_version",
    "agent_id",
    "sent_at",
    "capabilities",
    "spool_pending",
    "spool_oldest_seconds",
    "disk_free_bytes",
    "clock_offset_ms",
    "routes"
  ]
}
