{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "SelectionPoint": {
      "description": "A point in the document. Use {kind:'text', blockId, offset} for character positions or {kind:'nodeEdge', node:{kind:'block', nodeType, nodeId}, edge:'before'|'after'} for block boundaries.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "blockId": {
              "type": "string"
            },
            "offset": {
              "type": "integer",
              "minimum": 0
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "blockId",
            "offset"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "nodeEdge"
            },
            "node": {
              "$ref": "#/$defs/SelectionEdgeNodeAddress"
            },
            "edge": {
              "enum": [
                "before",
                "after"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "node",
            "edge"
          ]
        }
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    },
    "SelectionEdgeNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "SelectionTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "selection"
        },
        "start": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "end": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "start",
        "end"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    }
  },
  "operationId": "ranges.resolve",
  "schemas": {
    "input": {
      "type": "object",
      "properties": {
        "start": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "document"
                },
                "edge": {
                  "enum": [
                    "start",
                    "end"
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "edge"
              ]
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "point"
                },
                "point": {
                  "$ref": "#/$defs/SelectionPoint"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "point"
              ]
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "ref"
                },
                "ref": {
                  "type": "string",
                  "minLength": 1
                },
                "boundary": {
                  "enum": [
                    "start",
                    "end"
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "ref",
                "boundary"
              ]
            }
          ]
        },
        "end": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "document"
                },
                "edge": {
                  "enum": [
                    "start",
                    "end"
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "edge"
              ]
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "point"
                },
                "point": {
                  "$ref": "#/$defs/SelectionPoint"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "point"
              ]
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "ref"
                },
                "ref": {
                  "type": "string",
                  "minLength": 1
                },
                "boundary": {
                  "enum": [
                    "start",
                    "end"
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "ref",
                "boundary"
              ]
            }
          ]
        },
        "in": {
          "$ref": "#/$defs/StoryLocator"
        },
        "expectedRevision": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "start",
        "end"
      ]
    },
    "output": {
      "type": "object",
      "properties": {
        "evaluatedRevision": {
          "type": "string"
        },
        "handle": {
          "type": "object",
          "properties": {
            "ref": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "refStability": {
              "const": "ephemeral"
            },
            "coversFullTarget": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "required": [
            "ref",
            "refStability",
            "coversFullTarget"
          ]
        },
        "target": {
          "$ref": "#/$defs/SelectionTarget"
        },
        "preview": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            },
            "truncated": {
              "type": "boolean"
            },
            "blocks": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "nodeId": {
                    "type": "string"
                  },
                  "nodeType": {
                    "enum": [
                      "paragraph",
                      "heading",
                      "listItem",
                      "table",
                      "tableRow",
                      "tableCell",
                      "tableOfContents",
                      "image",
                      "sdt"
                    ]
                  },
                  "textPreview": {
                    "type": "string"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "nodeId",
                  "nodeType",
                  "textPreview"
                ]
              }
            }
          },
          "additionalProperties": false,
          "required": [
            "text",
            "truncated",
            "blocks"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "evaluatedRevision",
        "handle",
        "target",
        "preview"
      ]
    }
  }
}
