{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "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"
      ]
    },
    "TrackedChangeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "entity"
        },
        "entityType": {
          "const": "trackedChange"
        },
        "entityId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "entityType",
        "entityId"
      ]
    }
  },
  "operationId": "diff.apply",
  "schemas": {
    "input": {
      "type": "object",
      "properties": {
        "diff": {
          "type": "object",
          "properties": {
            "version": {
              "type": "string",
              "enum": [
                "sd-diff-payload/v1",
                "sd-diff-payload/v2"
              ]
            },
            "engine": {
              "type": "string",
              "enum": [
                "superdoc-v2"
              ]
            },
            "baseFingerprint": {
              "type": "string"
            },
            "targetFingerprint": {
              "type": "string"
            },
            "coverage": {
              "type": "object",
              "properties": {
                "body": {
                  "type": "boolean",
                  "const": true
                },
                "comments": {
                  "type": "boolean"
                },
                "styles": {
                  "type": "boolean"
                },
                "numbering": {
                  "type": "boolean"
                },
                "headerFooters": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "body",
                "comments",
                "styles",
                "numbering",
                "headerFooters"
              ]
            },
            "summary": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                },
                "changedComponents": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "body",
                      "comments",
                      "styles",
                      "numbering",
                      "headerFooters",
                      "parts"
                    ]
                  }
                },
                "body": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                },
                "comments": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                },
                "styles": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                },
                "numbering": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                },
                "headerFooters": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                },
                "parts": {
                  "type": "object",
                  "properties": {
                    "hasChanges": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "hasChanges"
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges",
                "changedComponents",
                "body",
                "comments",
                "styles",
                "numbering",
                "headerFooters",
                "parts"
              ]
            },
            "payload": {
              "type": "object",
              "description": "Opaque engine-owned diff data."
            }
          },
          "additionalProperties": false,
          "required": [
            "version",
            "engine",
            "baseFingerprint",
            "targetFingerprint",
            "coverage",
            "summary",
            "payload"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "diff"
      ]
    },
    "output": {
      "type": "object",
      "properties": {
        "appliedOperations": {
          "type": "integer"
        },
        "operationReceipts": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "operationId": {
                    "type": "string"
                  },
                  "disposition": {
                    "const": "review-created"
                  },
                  "reviewItems": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "story": {
                          "$ref": "#/$defs/StoryLocator"
                        },
                        "address": {
                          "$ref": "#/$defs/TrackedChangeAddress"
                        },
                        "navigationTarget": {
                          "type": "object",
                          "properties": {
                            "kind": {
                              "const": "block"
                            },
                            "story": {
                              "$ref": "#/$defs/StoryLocator"
                            },
                            "blockId": {
                              "type": "string"
                            },
                            "role": {
                              "enum": [
                                "primary",
                                "move-source",
                                "move-destination",
                                "formatting-carrier",
                                "structural-carrier"
                              ]
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "kind",
                            "story",
                            "blockId",
                            "role"
                          ]
                        }
                      },
                      "additionalProperties": false,
                      "required": [
                        "id",
                        "story",
                        "address"
                      ]
                    }
                  }
                },
                "additionalProperties": false,
                "required": [
                  "operationId",
                  "disposition",
                  "reviewItems"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "operationId": {
                    "type": "string"
                  },
                  "disposition": {
                    "const": "applied-directly"
                  },
                  "reviewItems": {
                    "type": "array",
                    "maxItems": 0
                  }
                },
                "additionalProperties": false,
                "required": [
                  "operationId",
                  "disposition",
                  "reviewItems"
                ]
              }
            ]
          }
        },
        "baseFingerprint": {
          "type": "string"
        },
        "targetFingerprint": {
          "type": "string"
        },
        "coverage": {
          "type": "object",
          "properties": {
            "body": {
              "type": "boolean",
              "const": true
            },
            "comments": {
              "type": "boolean"
            },
            "styles": {
              "type": "boolean"
            },
            "numbering": {
              "type": "boolean"
            },
            "headerFooters": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "required": [
            "body",
            "comments",
            "styles",
            "numbering",
            "headerFooters"
          ]
        },
        "summary": {
          "type": "object",
          "properties": {
            "hasChanges": {
              "type": "boolean"
            },
            "changedComponents": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "body",
                  "comments",
                  "styles",
                  "numbering",
                  "headerFooters",
                  "parts"
                ]
              }
            },
            "body": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "comments": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "styles": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "numbering": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "headerFooters": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "parts": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "hasChanges",
            "changedComponents",
            "body",
            "comments",
            "styles",
            "numbering",
            "headerFooters",
            "parts"
          ]
        },
        "diagnostics": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "appliedOperations",
        "operationReceipts",
        "baseFingerprint",
        "targetFingerprint",
        "coverage",
        "summary",
        "diagnostics"
      ]
    },
    "success": {
      "type": "object",
      "properties": {
        "appliedOperations": {
          "type": "integer"
        },
        "operationReceipts": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "operationId": {
                    "type": "string"
                  },
                  "disposition": {
                    "const": "review-created"
                  },
                  "reviewItems": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "story": {
                          "$ref": "#/$defs/StoryLocator"
                        },
                        "address": {
                          "$ref": "#/$defs/TrackedChangeAddress"
                        },
                        "navigationTarget": {
                          "type": "object",
                          "properties": {
                            "kind": {
                              "const": "block"
                            },
                            "story": {
                              "$ref": "#/$defs/StoryLocator"
                            },
                            "blockId": {
                              "type": "string"
                            },
                            "role": {
                              "enum": [
                                "primary",
                                "move-source",
                                "move-destination",
                                "formatting-carrier",
                                "structural-carrier"
                              ]
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "kind",
                            "story",
                            "blockId",
                            "role"
                          ]
                        }
                      },
                      "additionalProperties": false,
                      "required": [
                        "id",
                        "story",
                        "address"
                      ]
                    }
                  }
                },
                "additionalProperties": false,
                "required": [
                  "operationId",
                  "disposition",
                  "reviewItems"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "operationId": {
                    "type": "string"
                  },
                  "disposition": {
                    "const": "applied-directly"
                  },
                  "reviewItems": {
                    "type": "array",
                    "maxItems": 0
                  }
                },
                "additionalProperties": false,
                "required": [
                  "operationId",
                  "disposition",
                  "reviewItems"
                ]
              }
            ]
          }
        },
        "baseFingerprint": {
          "type": "string"
        },
        "targetFingerprint": {
          "type": "string"
        },
        "coverage": {
          "type": "object",
          "properties": {
            "body": {
              "type": "boolean",
              "const": true
            },
            "comments": {
              "type": "boolean"
            },
            "styles": {
              "type": "boolean"
            },
            "numbering": {
              "type": "boolean"
            },
            "headerFooters": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "required": [
            "body",
            "comments",
            "styles",
            "numbering",
            "headerFooters"
          ]
        },
        "summary": {
          "type": "object",
          "properties": {
            "hasChanges": {
              "type": "boolean"
            },
            "changedComponents": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "body",
                  "comments",
                  "styles",
                  "numbering",
                  "headerFooters",
                  "parts"
                ]
              }
            },
            "body": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "comments": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "styles": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "numbering": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "headerFooters": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            },
            "parts": {
              "type": "object",
              "properties": {
                "hasChanges": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false,
              "required": [
                "hasChanges"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "hasChanges",
            "changedComponents",
            "body",
            "comments",
            "styles",
            "numbering",
            "headerFooters",
            "parts"
          ]
        },
        "diagnostics": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "appliedOperations",
        "operationReceipts",
        "baseFingerprint",
        "targetFingerprint",
        "coverage",
        "summary",
        "diagnostics"
      ]
    },
    "failure": {
      "type": "object"
    }
  }
}
