{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "relay-result",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "protocol_version": {
      "const": 1
    },
    "attempt_id": {
      "type": "string",
      "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "route_version_id": {
      "type": "string",
      "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
    },
    "outcome": {
      "enum": [
        "response",
        "transport_error",
        "cancelled_before_dispatch"
      ]
    },
    "dispatched": {
      "type": "boolean"
    },
    "dispatch_uncertain": {
      "type": "boolean"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 100,
      "maximum": 599
    },
    "body_b64": {
      "type": "string",
      "contentEncoding": "base64",
      "maxLength": 174764
    },
    "body_sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "body_bytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 131072
    },
    "body_complete": {
      "type": "boolean"
    },
    "headers": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "content_type": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 256
        }
      },
      "required": [
        "content_type"
      ]
    },
    "rate_hints": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "remaining": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "reset_after_seconds": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "retry_after_seconds": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        }
      },
      "required": [
        "remaining",
        "reset_after_seconds",
        "retry_after_seconds"
      ]
    },
    "duration_ms": {
      "type": "integer",
      "minimum": 0
    },
    "received_at": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$"
    },
    "error_code": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 128
    }
  },
  "required": [
    "protocol_version",
    "attempt_id",
    "route_version_id",
    "outcome",
    "dispatched",
    "dispatch_uncertain",
    "status_code",
    "body_b64",
    "body_sha256",
    "body_bytes",
    "body_complete",
    "headers",
    "rate_hints",
    "duration_ms",
    "received_at",
    "error_code"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "response"
          }
        }
      },
      "then": {
        "properties": {
          "status_code": {
            "type": "integer"
          },
          "body_complete": {
            "const": true
          },
          "dispatched": {
            "const": true
          },
          "dispatch_uncertain": {
            "const": false
          },
          "error_code": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "cancelled_before_dispatch"
          }
        }
      },
      "then": {
        "properties": {
          "status_code": {
            "type": "null"
          },
          "dispatched": {
            "const": false
          },
          "dispatch_uncertain": {
            "const": false
          },
          "body_bytes": {
            "const": 0
          },
          "body_b64": {
            "const": ""
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "transport_error"
          }
        }
      },
      "then": {
        "properties": {
          "status_code": {
            "type": "null"
          },
          "body_complete": {
            "const": false
          }
        }
      }
    }
  ]
}
