{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:si:issue-page:1.3",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "connection_id",
    "generation_id",
    "sequence",
    "freshness",
    "items",
    "next_cursor",
    "trust_state"
  ],
  "properties": {
    "connection_id": {
      "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
    },
    "generation_id": {
      "anyOf": [
        {
          "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
        },
        {
          "type": "null"
        }
      ]
    },
    "sequence": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "freshness": {
      "enum": [
        "not_synced",
        "clock_untrusted",
        "stale",
        "partial",
        "current"
      ]
    },
    "items": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "$ref": "#/$defs/item"
      }
    },
    "next_cursor": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1,
      "maxLength": 2048
    },
    "trust_state": {
      "enum": [
        "unverified",
        "trust_busy",
        "clock_untrusted",
        "verification_interrupted",
        "catch_up_required",
        "not_synced",
        "aligned"
      ]
    }
  },
  "$defs": {
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "issue_id",
        "revision",
        "kind",
        "reason_code",
        "effective_at",
        "replacement_ids",
        "redacted",
        "payload"
      ],
      "properties": {
        "issue_id": {
          "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
        },
        "revision": {
          "$ref": "urn:si:feed-record:1.0#/$defs/revision"
        },
        "kind": {
          "enum": [
            "upsert",
            "withdraw",
            "relation_changed",
            "redact",
            "retire"
          ]
        },
        "reason_code": {
          "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
        },
        "effective_at": {
          "$ref": "urn:si:feed-record:1.0#/$defs/utcTime"
        },
        "replacement_ids": {
          "type": "array",
          "maxItems": 64,
          "uniqueItems": true,
          "items": {
            "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
          }
        },
        "redacted": {
          "type": "boolean"
        },
        "payload": {
          "anyOf": [
            {
              "anyOf": [
                {
                  "$ref": "urn:si:feed-record:1.0#/$defs/issue"
                },
                {
                  "$ref": "urn:si:feed-record:1.1#/$defs/issue"
                },
                {
                  "$ref": "urn:si:feed-record:1.2#/$defs/issue"
                },
                {
                  "$ref": "urn:si:feed-record:1.3#/$defs/issue"
                }
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "redact"
              }
            }
          },
          "then": {
            "properties": {
              "payload": {
                "type": "null"
              },
              "redacted": {
                "const": true
              }
            }
          },
          "else": {
            "properties": {
              "payload": {
                "anyOf": [
                  {
                    "$ref": "urn:si:feed-record:1.0#/$defs/issue"
                  },
                  {
                    "$ref": "urn:si:feed-record:1.1#/$defs/issue"
                  },
                  {
                    "$ref": "urn:si:feed-record:1.2#/$defs/issue"
                  },
                  {
                    "$ref": "urn:si:feed-record:1.3#/$defs/issue"
                  }
                ]
              },
              "redacted": {
                "const": false
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "withdraw"
              }
            }
          },
          "then": {
            "properties": {
              "payload": {
                "properties": {
                  "publication_state": {
                    "const": "withdrawn"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "retire"
              }
            }
          },
          "then": {
            "properties": {
              "payload": {
                "properties": {
                  "support_state": {
                    "const": "retired"
                  }
                }
              }
            }
          }
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "sequence": {
            "const": 0
          }
        }
      },
      "then": {
        "properties": {
          "generation_id": {
            "type": "null"
          },
          "items": {
            "maxItems": 0
          },
          "next_cursor": {
            "type": "null"
          },
          "freshness": {
            "const": "not_synced"
          }
        }
      },
      "else": {
        "properties": {
          "generation_id": {
            "$ref": "urn:si:feed-record:1.0#/$defs/identifier"
          }
        }
      }
    }
  ]
}
