{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/binding.schema.json",
  "type": "object",
  "properties": {
    "scopeId": {
      "type": "string",
      "minLength": 1
    },
    "interactionId": {
      "type": "string",
      "minLength": 1
    },
    "documentId": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "instanceId": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "contextId": {
      "type": "string",
      "minLength": 1
    },
    "selectionRevision": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "role": {
      "enum": [
        "reader-admin",
        "redbook-admin",
        "digital"
      ]
    },
    "digitalId": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "editCounter": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "capabilityRevision": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    }
  },
  "required": [
    "scopeId",
    "interactionId",
    "documentId",
    "instanceId",
    "contextId",
    "selectionRevision",
    "role",
    "digitalId",
    "editCounter",
    "capabilityRevision"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "role": {
            "const": "digital"
          }
        }
      },
      "then": {
        "properties": {
          "digitalId": {
            "type": "string",
            "minLength": 1
          },
          "documentId": {
            "type": "string",
            "minLength": 1
          },
          "instanceId": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "else": {
        "properties": {
          "digitalId": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "role": {
            "const": "reader-admin"
          }
        }
      },
      "then": {
        "properties": {
          "documentId": {
            "type": "null"
          },
          "instanceId": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "documentId": {
            "type": "string",
            "minLength": 1
          },
          "instanceId": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  ]
}
