{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://security-intelligence.invalid/contracts/feed-record/1.0",
  "title": "Public issue operation 1.0",
  "type": "object",
  "additionalProperties": false,
  "required": ["record_contract_version", "operation_id", "object_type", "object_id", "previous_revision", "revision", "kind", "reason_code", "replacement_ids", "effective_at", "payload"],
  "properties": {
    "record_contract_version": { "const": "1.0" },
    "operation_id": { "$ref": "#/$defs/identifier" },
    "object_type": { "const": "issue" },
    "object_id": { "$ref": "#/$defs/identifier" },
    "previous_revision": { "anyOf": [{ "$ref": "#/$defs/revision" }, { "type": "null" }] },
    "revision": { "$ref": "#/$defs/revision" },
    "kind": { "enum": ["upsert", "withdraw", "relation_changed", "redact", "retire"] },
    "reason_code": { "$ref": "#/$defs/identifier" },
    "replacement_ids": { "type": "array", "maxItems": 64, "uniqueItems": true, "items": { "$ref": "#/$defs/identifier" } },
    "effective_at": { "$ref": "#/$defs/utcTime" },
    "payload": { "anyOf": [{ "$ref": "#/$defs/issue" }, { "type": "null" }] }
  },
  "allOf": [
    { "if": { "properties": { "kind": { "const": "redact" } } }, "then": { "properties": { "payload": { "type": "null" } } }, "else": { "properties": { "payload": { "$ref": "#/$defs/issue" } } } },
    { "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" } } } } } }
  ],
  "$defs": {
    "identifier": { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$", "not": { "pattern": "[^A-Za-z0-9._:-]" } },
    "revision": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
    "utcTime": { "type": "string", "minLength": 20, "maxLength": 20, "format": "date-time", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$" },
    "issue": {
      "type": "object", "additionalProperties": false,
      "required": ["title", "summary", "identifiers", "confirmation", "source_state", "publication_state", "support_state", "source_references", "relations"],
      "properties": {
        "title": { "type": "string", "minLength": 1, "maxLength": 1024 },
        "summary": { "type": ["string", "null"], "maxLength": 32768 },
        "identifiers": {
          "type": "array", "minItems": 1, "maxItems": 64, "uniqueItems": true,
          "items": {
            "type": "object", "additionalProperties": false, "required": ["namespace", "id"],
            "properties": { "namespace": { "$ref": "#/$defs/identifier" }, "id": { "$ref": "#/$defs/identifier" } }
          }
        },
        "confirmation": { "enum": ["candidate", "corroborated", "vendor_confirmed", "disputed", "rejected"] },
        "source_state": { "enum": ["active", "corrected", "withdrawn", "conflicting"] },
        "publication_state": { "enum": ["published", "corrected", "withdrawn"] },
        "support_state": { "enum": ["active", "retired", "unknown"] },
        "source_references": {
          "type": "array", "minItems": 1, "maxItems": 64, "uniqueItems": true,
          "items": {
            "type": "object", "additionalProperties": false, "required": ["source_id", "record_id", "revision", "url", "relationship"],
            "properties": {
              "source_id": { "$ref": "#/$defs/identifier" }, "record_id": { "$ref": "#/$defs/identifier" }, "revision": { "$ref": "#/$defs/identifier" },
              "url": { "type": "string", "minLength": 1, "maxLength": 4096, "format": "uri" },
              "relationship": { "enum": ["supports", "refutes", "quotes", "derived_from"] }
            }
          }
        },
        "relations": {
          "type": "array", "maxItems": 128, "uniqueItems": true,
          "items": {
            "type": "object", "additionalProperties": false, "required": ["kind", "issue_id"],
            "properties": { "kind": { "enum": ["same_as", "upstream_of", "related_to", "possibly_related"] }, "issue_id": { "$ref": "#/$defs/identifier" } }
          }
        }
      }
    }
  }
}
