{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "TextTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "text"
        },
        "segments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TextSegment"
          },
          "minItems": 1
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "segments"
      ]
    },
    "TextSegment": {
      "type": "object",
      "properties": {
        "blockId": {
          "type": "string"
        },
        "range": {
          "$ref": "#/$defs/Range"
        }
      },
      "additionalProperties": false,
      "required": [
        "blockId",
        "range"
      ]
    },
    "Range": {
      "type": "object",
      "properties": {
        "start": {
          "type": "integer"
        },
        "end": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "start",
        "end"
      ]
    },
    "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"
      ]
    },
    "InlineAnchor": {
      "type": "object",
      "properties": {
        "start": {
          "$ref": "#/$defs/Position"
        },
        "end": {
          "$ref": "#/$defs/Position"
        }
      },
      "additionalProperties": false,
      "required": [
        "start",
        "end"
      ]
    },
    "Position": {
      "type": "object",
      "properties": {
        "blockId": {
          "type": "string"
        },
        "offset": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "required": [
        "blockId",
        "offset"
      ]
    }
  },
  "operationId": "index.entries.insert",
  "schemas": {
    "input": {
      "type": "object",
      "properties": {
        "at": {
          "$ref": "#/$defs/TextTarget"
        },
        "entry": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            },
            "subEntry": {
              "type": "string"
            },
            "bold": {
              "type": "boolean"
            },
            "italic": {
              "type": "boolean"
            },
            "crossReference": {
              "type": "string"
            },
            "pageRangeBookmark": {
              "type": "string"
            },
            "entryType": {
              "type": "string"
            },
            "yomi": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "text"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "at",
        "entry"
      ]
    },
    "output": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "success": {
              "const": true
            },
            "entry": {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "inline"
                },
                "nodeType": {
                  "const": "indexEntry"
                },
                "anchor": {
                  "$ref": "#/$defs/InlineAnchor"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "nodeType",
                "anchor"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "success",
            "entry"
          ]
        },
        {
          "type": "object",
          "properties": {
            "success": {
              "const": false
            },
            "failure": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                },
                "details": {}
              },
              "additionalProperties": false,
              "required": [
                "code",
                "message"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "success",
            "failure"
          ]
        }
      ]
    },
    "success": {
      "type": "object",
      "properties": {
        "success": {
          "const": true
        },
        "entry": {
          "type": "object",
          "properties": {
            "kind": {
              "const": "inline"
            },
            "nodeType": {
              "const": "indexEntry"
            },
            "anchor": {
              "$ref": "#/$defs/InlineAnchor"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "nodeType",
            "anchor"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success",
        "entry"
      ]
    },
    "failure": {
      "type": "object",
      "properties": {
        "success": {
          "const": false
        },
        "failure": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "details": {}
          },
          "additionalProperties": false,
          "required": [
            "code",
            "message"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "success",
        "failure"
      ]
    }
  }
}
