{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://local.codex/presentation-forge/editor-patch.schema.json",
  "title": "Presentation Forge Editor Patch",
  "type": "object",
  "required": ["schema_version", "request_id", "base_revision", "document_sha256", "canvas_sha256", "operations"],
  "properties": {
    "schema_version": {"const": 3},
    "request_id": {"type": "string", "minLength": 1},
    "base_revision": {"type": ["string", "null"]},
    "document_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "canvas_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "operations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "required": ["op", "path", "value"],
            "properties": {"op": {"const": "replace"}, "path": {"type": "string", "pattern": "^/"}, "value": {}}
          },
          {
            "type": "object",
            "required": ["op", "slide_number", "element_id", "changes"],
            "properties": {
              "op": {"const": "update-element"},
              "slide_number": {"type": "integer", "minimum": 1},
              "element_id": {"type": "string", "minLength": 1},
              "changes": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "bbox": {"type": "array", "minItems": 4, "maxItems": 4, "items": {"type": "number"}},
                  "text": {"type": "string"},
                  "style": {"type": "object"},
                  "rotation": {"type": "number"},
                  "z_index": {"type": "integer", "minimum": 0}
                }
              }
            }
          },
          {
            "type": "object",
            "required": ["op", "scope", "style_id", "variant_id", "mode"],
            "properties": {
              "op": {"const": "apply-style"},
              "scope": {"enum": ["deck", "slide"]},
              "slide_number": {"type": "integer", "minimum": 1},
              "style_id": {"type": "string", "minLength": 1},
              "variant_id": {"type": "string", "minLength": 1},
              "mode": {"enum": ["replace-theme", "preserve-layout"]}
            },
            "allOf": [
              {"if": {"properties": {"scope": {"const": "slide"}}}, "then": {"required": ["slide_number"]}}
            ]
          }
        ]
      }
    }
  }
}
