{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Webhook retained-history gap",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "v": {
          "type": "number",
          "const": 1
        },
        "kind": {
          "type": "string",
          "const": "history_gap"
        },
        "type": {
          "type": "string",
          "const": "webhook.history_gap"
        },
        "code": {
          "type": "string",
          "const": "CURSOR_EXPIRED"
        },
        "id": {
          "type": "string"
        },
        "feed": {
          "type": "string",
          "const": "events"
        },
        "workspace_id": {
          "type": "string"
        },
        "project_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T.*(?:Z|[+-]\\d{2}:\\d{2})$"
        },
        "computed": {
          "type": "boolean",
          "const": false
        },
        "totals": {
          "type": "null"
        },
        "resync_required": {
          "type": "boolean",
          "const": true
        },
        "history_gap": {
          "type": "object",
          "properties": {
            "after_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "through_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "scope": {
              "type": "string",
              "const": "workspace_feed"
            },
            "reason": {
              "type": "string",
              "const": "history_unavailable"
            },
            "affected_project_events": {
              "type": "string",
              "const": "unknown"
            }
          },
          "required": [
            "after_sequence",
            "through_sequence",
            "scope",
            "reason",
            "affected_project_events"
          ],
          "additionalProperties": false
        },
        "snapshot_endpoint": {
          "type": "string",
          "pattern": "^/v1/exports/watches(?:\\?projectId=[^#]*)?$"
        },
        "resume_cursor": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "resume": {
          "type": "object",
          "properties": {
            "feed": {
              "type": "string",
              "const": "events"
            },
            "after_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "endpoint": {
              "type": "string",
              "pattern": "^/v1/events(?:\\?projectId=[^#]*)?$"
            }
          },
          "required": [
            "feed",
            "after_sequence",
            "endpoint"
          ],
          "additionalProperties": false
        },
        "delivery_mode": {
          "type": "string",
          "const": "digest"
        },
        "window": {
          "type": "object",
          "properties": {
            "opened_at": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T.*(?:Z|[+-]\\d{2}:\\d{2})$"
            },
            "closed_at": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T.*(?:Z|[+-]\\d{2}:\\d{2})$"
            }
          },
          "required": [
            "opened_at",
            "closed_at"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "v",
        "kind",
        "type",
        "code",
        "id",
        "feed",
        "workspace_id",
        "project_id",
        "created_at",
        "computed",
        "totals",
        "resync_required",
        "history_gap",
        "snapshot_endpoint",
        "resume_cursor",
        "resume"
      ],
      "additionalProperties": false,
      "dependentRequired": {
        "delivery_mode": [
          "window"
        ],
        "window": [
          "delivery_mode"
        ]
      }
    },
    {
      "type": "object",
      "properties": {
        "v": {
          "type": "number",
          "const": 1
        },
        "kind": {
          "type": "string",
          "const": "history_gap"
        },
        "type": {
          "type": "string",
          "const": "webhook.history_gap"
        },
        "code": {
          "type": "string",
          "const": "CURSOR_EXPIRED"
        },
        "id": {
          "type": "string"
        },
        "feed": {
          "type": "string",
          "const": "target_events"
        },
        "workspace_id": {
          "type": "string"
        },
        "project_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T.*(?:Z|[+-]\\d{2}:\\d{2})$"
        },
        "computed": {
          "type": "boolean",
          "const": false
        },
        "totals": {
          "type": "null"
        },
        "resync_required": {
          "type": "boolean",
          "const": true
        },
        "history_gap": {
          "type": "object",
          "properties": {
            "after_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "through_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "scope": {
              "type": "string",
              "const": "workspace_feed"
            },
            "reason": {
              "type": "string",
              "const": "history_unavailable"
            },
            "affected_project_events": {
              "type": "string",
              "const": "unknown"
            }
          },
          "required": [
            "after_sequence",
            "through_sequence",
            "scope",
            "reason",
            "affected_project_events"
          ],
          "additionalProperties": false
        },
        "snapshot_endpoint": {
          "type": "string",
          "pattern": "^/v1/targets(?:\\?projectId=[^#]*)?$"
        },
        "resume_cursor": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "resume": {
          "type": "object",
          "properties": {
            "feed": {
              "type": "string",
              "const": "target_events"
            },
            "after_sequence": {
              "type": "integer",
              "minimum": 0
            },
            "endpoint": {
              "type": "string",
              "pattern": "^/v1/target-events(?:\\?projectId=[^#]*)?$"
            }
          },
          "required": [
            "feed",
            "after_sequence",
            "endpoint"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "v",
        "kind",
        "type",
        "code",
        "id",
        "feed",
        "workspace_id",
        "project_id",
        "created_at",
        "computed",
        "totals",
        "resync_required",
        "history_gap",
        "snapshot_endpoint",
        "resume_cursor",
        "resume"
      ],
      "additionalProperties": false
    }
  ]
}
