{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.publisher.example/connector/draft-0.2",
  "$defs": {
    "uuid": {
      "type": "string",
      "pattern": "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
    },
    "hash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "utc": {
      "type": "string",
      "format": "publisher-utc",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
    },
    "positiveInt": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "apiBase": {
      "type": "string",
      "maxLength": 2048,
      "pattern": "^https://[a-z0-9.-]+/(?:[A-Za-z0-9_-]+/)*$"
    },
    "capability": {
      "enum": [
        "site.read",
        "operation.read",
        "media.upload",
        "draft.create",
        "draft.update",
        "published.update",
        "publication.publish"
      ]
    },
    "code": {
      "type": "string",
      "minLength": 43,
      "maxLength": 43,
      "pattern": "^[A-Za-z0-9_-]{43}$"
    },
    "policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "revision",
        "execution_user_id",
        "allowed_author_ids",
        "allowed_category_ids",
        "capabilities",
        "html_profile"
      ],
      "properties": {
        "revision": {
          "$ref": "#/$defs/positiveInt"
        },
        "execution_user_id": {
          "$ref": "#/$defs/positiveInt"
        },
        "allowed_author_ids": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/positiveInt"
          },
          "minItems": 1,
          "maxItems": 100,
          "uniqueItems": true
        },
        "allowed_category_ids": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/positiveInt"
          },
          "minItems": 0,
          "maxItems": 10000,
          "uniqueItems": true
        },
        "capabilities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/capability"
          },
          "minItems": 2,
          "maxItems": 7,
          "uniqueItems": true
        },
        "html_profile": {
          "const": "publisher-post-html-v1"
        },
        "category_scope": {
          "enum": [
            "all_accessible"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "category_scope"
            ]
          },
          "then": {
            "properties": {
              "revision": {
                "minimum": 2
              }
            }
          },
          "else": {
            "properties": {
              "allowed_category_ids": {
                "minItems": 1,
                "maxItems": 100
              }
            }
          }
        }
      ]
    },
    "authorization": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "approval_id",
        "approved_at",
        "expires_at",
        "actor_ref",
        "claim_hash",
        "write_budget"
      ],
      "properties": {
        "approval_id": {
          "$ref": "#/$defs/uuid"
        },
        "approved_at": {
          "$ref": "#/$defs/utc"
        },
        "expires_at": {
          "$ref": "#/$defs/utc"
        },
        "actor_ref": {
          "$ref": "#/$defs/uuid"
        },
        "claim_hash": {
          "$ref": "#/$defs/hash"
        },
        "write_budget": {
          "const": 1
        }
      }
    },
    "media": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "filename",
        "mime_type",
        "sha256",
        "bytes_base64",
        "alt_text",
        "credit"
      ],
      "properties": {
        "filename": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
        },
        "mime_type": {
          "enum": [
            "image/png",
            "image/jpeg"
          ]
        },
        "sha256": {
          "$ref": "#/$defs/hash"
        },
        "bytes_base64": {
          "type": "string",
          "minLength": 4,
          "maxLength": 11184812,
          "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
        },
        "alt_text": {
          "type": "string",
          "minLength": 0,
          "maxLength": 500
        },
        "credit": {
          "type": "string",
          "minLength": 0,
          "maxLength": 500
        }
      }
    },
    "projection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "title",
        "slug",
        "excerpt",
        "body_html",
        "author_id",
        "category_ids",
        "media_handle"
      ],
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "slug": {
          "type": "string",
          "maxLength": 200,
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "excerpt": {
          "type": "string",
          "minLength": 0,
          "maxLength": 1000
        },
        "body_html": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100000
        },
        "author_id": {
          "$ref": "#/$defs/positiveInt"
        },
        "category_ids": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/positiveInt"
          },
          "minItems": 1,
          "maxItems": 100,
          "uniqueItems": true
        },
        "media_handle": {
          "anyOf": [
            {
              "$ref": "#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "publication": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "draft_handle",
        "expected_draft_hash",
        "projection"
      ],
      "properties": {
        "mode": {
          "enum": [
            "create_draft",
            "create_publish",
            "publish_draft",
            "amend_draft",
            "amend_published"
          ]
        },
        "draft_handle": {
          "anyOf": [
            {
              "$ref": "#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "expected_draft_hash": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "projection": {
          "$ref": "#/$defs/projection"
        },
        "canonical_url": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048
            },
            {
              "type": "null"
            }
          ]
        },
        "post_id": {
          "anyOf": [
            {
              "$ref": "#/$defs/positiveInt"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "enum": [
                  "publish_draft",
                  "amend_draft"
                ]
              }
            },
            "required": [
              "mode"
            ]
          },
          "then": {
            "properties": {
              "draft_handle": {
                "$ref": "#/$defs/uuid"
              },
              "expected_draft_hash": {
                "$ref": "#/$defs/hash"
              }
            }
          },
          "else": {
            "properties": {
              "draft_handle": {
                "type": "null"
              },
              "expected_draft_hash": {
                "anyOf": [
                  {
                    "$ref": "#/$defs/hash"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "mode": {
                "const": "amend_published"
              }
            },
            "required": [
              "mode"
            ]
          },
          "then": {
            "required": [
              "canonical_url",
              "post_id"
            ],
            "properties": {
              "draft_handle": {
                "type": "null"
              },
              "expected_draft_hash": {
                "$ref": "#/$defs/hash"
              },
              "canonical_url": {
                "type": "string"
              },
              "post_id": {
                "$ref": "#/$defs/positiveInt"
              }
            }
          },
          "else": {
            "properties": {
              "canonical_url": {
                "type": "null"
              },
              "post_id": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "mediaRequest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "idempotency_key",
        "effect_id",
        "policy_hash",
        "subject_hash",
        "target_fingerprint",
        "authorization",
        "operation",
        "media"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "effect_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "subject_hash": {
          "$ref": "#/$defs/hash"
        },
        "target_fingerprint": {
          "$ref": "#/$defs/hash"
        },
        "authorization": {
          "$ref": "#/$defs/authorization"
        },
        "operation": {
          "const": "media.upload"
        },
        "media": {
          "$ref": "#/$defs/media"
        }
      }
    },
    "publicationRequest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "idempotency_key",
        "effect_id",
        "policy_hash",
        "subject_hash",
        "target_fingerprint",
        "authorization",
        "operation",
        "publication"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "effect_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "subject_hash": {
          "$ref": "#/$defs/hash"
        },
        "target_fingerprint": {
          "$ref": "#/$defs/hash"
        },
        "authorization": {
          "$ref": "#/$defs/authorization"
        },
        "operation": {
          "enum": [
            "publication.create_draft",
            "publication.create_publish",
            "publication.publish_draft",
            "publication.amend_draft",
            "publication.amend_published"
          ]
        },
        "publication": {
          "$ref": "#/$defs/publication"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "operation": {
                "const": "publication.create_draft"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "publication": {
                "properties": {
                  "mode": {
                    "const": "create_draft"
                  }
                },
                "required": [
                  "mode"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "operation": {
                "const": "publication.amend_draft"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "publication": {
                "properties": {
                  "mode": {
                    "const": "amend_draft"
                  }
                },
                "required": [
                  "mode"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "operation": {
                "const": "publication.create_publish"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "publication": {
                "properties": {
                  "mode": {
                    "const": "create_publish"
                  }
                },
                "required": [
                  "mode"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "operation": {
                "const": "publication.publish_draft"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "publication": {
                "properties": {
                  "mode": {
                    "const": "publish_draft"
                  }
                },
                "required": [
                  "mode"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "operation": {
                "const": "publication.amend_published"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "publication": {
                "properties": {
                  "mode": {
                    "const": "amend_published"
                  }
                },
                "required": [
                  "mode"
                ]
              }
            }
          }
        }
      ]
    },
    "pairingConfirm": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "operation",
        "idempotency_key",
        "policy_hash",
        "consent_hash",
        "challenge",
        "challenge_hash",
        "expires_at"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "operation": {
          "const": "pairing.confirm"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "consent_hash": {
          "$ref": "#/$defs/hash"
        },
        "challenge": {
          "$ref": "#/$defs/hash"
        },
        "challenge_hash": {
          "$ref": "#/$defs/hash"
        },
        "expires_at": {
          "$ref": "#/$defs/utc"
        }
      }
    },
    "pairingStatus": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "key_id",
        "api_base",
        "state",
        "policy_hash",
        "expires_at",
        "consent_hash",
        "challenge_hash",
        "confirmation_key"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "key_id": {
          "$ref": "#/$defs/uuid"
        },
        "api_base": {
          "$ref": "#/$defs/apiBase"
        },
        "state": {
          "enum": [
            "pending_consent",
            "consented",
            "active"
          ]
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "expires_at": {
          "$ref": "#/$defs/utc"
        },
        "consent_hash": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "challenge_hash": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "confirmation_key": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "state": {
                "const": "active"
              }
            },
            "required": [
              "state"
            ]
          },
          "then": {
            "properties": {
              "consent_hash": {
                "$ref": "#/$defs/hash"
              },
              "challenge_hash": {
                "$ref": "#/$defs/hash"
              },
              "confirmation_key": {
                "$ref": "#/$defs/hash"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "state": {
                "const": "pending_consent"
              }
            },
            "required": [
              "state"
            ]
          },
          "then": {
            "properties": {
              "consent_hash": {
                "type": "null"
              },
              "challenge_hash": {
                "type": "null"
              },
              "confirmation_key": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "state": {
                "const": "consented"
              }
            },
            "required": [
              "state"
            ]
          },
          "then": {
            "properties": {
              "consent_hash": {
                "$ref": "#/$defs/hash"
              },
              "challenge_hash": {
                "$ref": "#/$defs/hash"
              },
              "confirmation_key": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "capabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "policy_hash",
        "policy",
        "limits"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "policy": {
          "$ref": "#/$defs/policy"
        },
        "limits": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "wire_bytes",
            "media_bytes",
            "image_pixels",
            "image_dimension",
            "clock_skew_seconds",
            "nonce_retention_seconds",
            "approval_max_seconds"
          ],
          "properties": {
            "wire_bytes": {
              "const": 12582912
            },
            "media_bytes": {
              "const": 8388608
            },
            "image_pixels": {
              "const": 24000000
            },
            "image_dimension": {
              "const": 8192
            },
            "clock_skew_seconds": {
              "const": 300
            },
            "nonce_retention_seconds": {
              "const": 660
            },
            "approval_max_seconds": {
              "const": 900
            }
          }
        }
      }
    },
    "codeExchange": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "code",
        "installation_id",
        "api_base",
        "policy"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "code": {
          "$ref": "#/$defs/code"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "api_base": {
          "$ref": "#/$defs/apiBase"
        },
        "policy": {
          "$ref": "#/$defs/policy"
        }
      }
    },
    "codeExchangeResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "tenant_label",
        "key_id",
        "secret",
        "api_base",
        "policy",
        "policy_hash",
        "expires_at"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "tenant_label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "key_id": {
          "$ref": "#/$defs/uuid"
        },
        "secret": {
          "$ref": "#/$defs/code"
        },
        "api_base": {
          "$ref": "#/$defs/apiBase"
        },
        "policy": {
          "$ref": "#/$defs/policy"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "expires_at": {
          "$ref": "#/$defs/utc"
        }
      }
    },
    "consentNotice": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "idempotency_key",
        "operation",
        "api_base",
        "policy_hash",
        "admin_user_id",
        "consented_at",
        "consent_hash",
        "challenge",
        "challenge_hash",
        "expires_at"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "operation": {
          "const": "pairing.consent"
        },
        "api_base": {
          "$ref": "#/$defs/apiBase"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "admin_user_id": {
          "$ref": "#/$defs/positiveInt"
        },
        "consented_at": {
          "$ref": "#/$defs/utc"
        },
        "consent_hash": {
          "$ref": "#/$defs/hash"
        },
        "challenge": {
          "$ref": "#/$defs/hash"
        },
        "challenge_hash": {
          "$ref": "#/$defs/hash"
        },
        "expires_at": {
          "$ref": "#/$defs/utc"
        }
      }
    },
    "mediaResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "media_handle",
        "attachment_id",
        "original_sha256"
      ],
      "properties": {
        "kind": {
          "const": "media"
        },
        "media_handle": {
          "$ref": "#/$defs/uuid"
        },
        "attachment_id": {
          "$ref": "#/$defs/positiveInt"
        },
        "original_sha256": {
          "$ref": "#/$defs/hash"
        }
      }
    },
    "publicationResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "publication_handle",
        "post_id",
        "status",
        "projection",
        "content_hash",
        "public_url"
      ],
      "properties": {
        "kind": {
          "const": "publication"
        },
        "publication_handle": {
          "anyOf": [
            {
              "$ref": "#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "post_id": {
          "$ref": "#/$defs/positiveInt"
        },
        "status": {
          "enum": [
            "draft",
            "publish"
          ]
        },
        "projection": {
          "$ref": "#/$defs/projection"
        },
        "content_hash": {
          "$ref": "#/$defs/hash"
        },
        "public_url": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 2048,
              "pattern": "^https://[^\\s]+$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "draft"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "public_url": {
                "type": "null"
              }
            }
          },
          "else": {
            "properties": {
              "public_url": {
                "type": "string"
              }
            }
          }
        }
      ]
    },
    "receipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "original_connection_id",
        "effect_id",
        "operation",
        "idempotency_key",
        "subject_hash",
        "target_fingerprint",
        "policy_hash",
        "state",
        "write_attempted",
        "receipt_hash",
        "result"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "original_connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "effect_id": {
          "$ref": "#/$defs/uuid"
        },
        "operation": {
          "enum": [
            "media.upload",
            "publication.create_draft",
            "publication.create_publish",
            "publication.publish_draft",
            "publication.amend_draft",
            "publication.amend_published"
          ]
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "subject_hash": {
          "$ref": "#/$defs/hash"
        },
        "target_fingerprint": {
          "$ref": "#/$defs/hash"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "state": {
          "const": "completed"
        },
        "write_attempted": {
          "const": true
        },
        "receipt_hash": {
          "$ref": "#/$defs/hash"
        },
        "result": {
          "oneOf": [
            {
              "$ref": "#/$defs/mediaResult"
            },
            {
              "$ref": "#/$defs/publicationResult"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "operation": {
                "const": "media.upload"
              }
            },
            "required": [
              "operation"
            ]
          },
          "then": {
            "properties": {
              "result": {
                "$ref": "#/$defs/mediaResult"
              }
            }
          },
          "else": {
            "properties": {
              "result": {
                "$ref": "#/$defs/publicationResult"
              }
            }
          }
        }
      ]
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state",
        "observed_at",
        "content_hash",
        "reason"
      ],
      "properties": {
        "state": {
          "enum": [
            "match",
            "mismatch",
            "absent",
            "unknown"
          ]
        },
        "observed_at": {
          "$ref": "#/$defs/utc"
        },
        "content_hash": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "reason": {
          "enum": [
            "none",
            "content_drift",
            "status_drift",
            "object_absent",
            "identity_ambiguous",
            "read_failed"
          ]
        }
      }
    },
    "operationStatus": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "idempotency_key",
        "state",
        "receipt",
        "observed"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "state": {
          "enum": [
            "completed",
            "unresolved"
          ]
        },
        "receipt": {
          "anyOf": [
            {
              "$ref": "#/$defs/receipt"
            },
            {
              "type": "null"
            }
          ]
        },
        "observed": {
          "anyOf": [
            {
              "$ref": "#/$defs/observation"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "state": {
                "const": "completed"
              }
            },
            "required": [
              "state"
            ]
          },
          "then": {
            "properties": {
              "receipt": {
                "$ref": "#/$defs/receipt"
              },
              "observed": {
                "$ref": "#/$defs/observation"
              }
            }
          },
          "else": {
            "properties": {
              "receipt": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "disconnectNotice": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "operation",
        "idempotency_key",
        "revoked_at"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "operation": {
          "const": "pairing.disconnect"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "revoked_at": {
          "$ref": "#/$defs/utc"
        }
      }
    },
    "publicationLookup": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "policy_hash",
        "canonical_url",
        "post_id",
        "status",
        "title",
        "content",
        "category_ids",
        "featured_media_id"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "canonical_url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "post_id": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        },
        "status": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        },
        "title": {
          "type": "string",
          "maxLength": 1000
        },
        "content": {
          "type": "string",
          "maxLength": 100000
        },
        "category_ids": {
          "type": "array",
          "maxItems": 100,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2147483647
          }
        },
        "featured_media_id": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            },
            {
              "type": "null"
            }
          ]
        },
        "projection": {
          "$ref": "#/$defs/projection"
        },
        "content_hash": {
          "$ref": "#/$defs/hash"
        }
      }
    },
    "historicalControlRequest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "policy_hash",
        "idempotency_key",
        "operation",
        "original_key_id",
        "original_request"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "idempotency_key": {
          "$ref": "#/$defs/hash"
        },
        "operation": {
          "const": "operation.control"
        },
        "original_key_id": {
          "$ref": "#/$defs/uuid"
        },
        "original_request": {
          "oneOf": [
            {
              "$ref": "#/$defs/mediaRequest"
            },
            {
              "$ref": "#/$defs/publicationRequest"
            }
          ]
        }
      }
    },
    "siteOptions": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "protocol_version",
        "tenant_id",
        "site_id",
        "installation_id",
        "connection_id",
        "policy_hash",
        "authors",
        "categories"
      ],
      "properties": {
        "protocol_version": {
          "const": 1
        },
        "tenant_id": {
          "$ref": "#/$defs/uuid"
        },
        "site_id": {
          "$ref": "#/$defs/uuid"
        },
        "installation_id": {
          "$ref": "#/$defs/uuid"
        },
        "connection_id": {
          "$ref": "#/$defs/uuid"
        },
        "policy_hash": {
          "$ref": "#/$defs/hash"
        },
        "authors": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/positiveInt"
              },
              "name": {
                "type": "string",
                "maxLength": 512
              }
            }
          }
        },
        "categories": {
          "type": "array",
          "maxItems": 10000,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "$ref": "#/$defs/positiveInt"
              },
              "name": {
                "type": "string",
                "maxLength": 512
              }
            }
          }
        }
      }
    }
  }
}
