{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "dispatch-permit",
  "oneOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "attempt_id": {
          "type": "string",
          "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
        },
        "granted": {
          "const": true
        },
        "state_generation": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "permit_id": {
          "type": "string",
          "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
        },
        "quota_group_id": {
          "type": "string",
          "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
        },
        "admitted_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$"
        },
        "dispatch_expires_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$"
        }
      },
      "required": [
        "attempt_id",
        "granted",
        "state_generation",
        "permit_id",
        "quota_group_id",
        "admitted_at",
        "dispatch_expires_at"
      ]
    },
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "attempt_id": {
          "type": "string",
          "pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
        },
        "granted": {
          "const": false
        },
        "state_generation": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "reason": {
          "enum": [
            "already_claimed",
            "capacity",
            "cooldown",
            "quarantine",
            "route_ineligible",
            "request_expired",
            "retry_budget"
          ]
        },
        "retry_after_ms": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "attempt_id",
        "granted",
        "state_generation",
        "reason",
        "retry_after_ms"
      ]
    }
  ]
}
