{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.example.invalid/schemas/exam-event-v1.json",
  "title": "KubData — eventos públicos v1",
  "$comment": "Contrato proposto. job.completed cobre classificação com artefato tipado. Eventos de expansão serão especificados em versões futuras.",
  "type": "object",
  "required": [
    "specversion",
    "id",
    "source",
    "type",
    "subject",
    "time",
    "datacontenttype",
    "tenantid",
    "correlationid",
    "aggregateversion",
    "data"
  ],
  "properties": {
    "specversion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "source": {
      "type": "string",
      "format": "uri"
    },
    "type": {
      "enum": [
        "document.version.published.v1",
        "question.updated.v1",
        "certification.changed.v1",
        "job.completed.v1",
        "analysis.ready.v1"
      ]
    },
    "subject": {
      "type": "string",
      "minLength": 1
    },
    "time": {
      "type": "string",
      "format": "date-time"
    },
    "datacontenttype": {
      "const": "application/json"
    },
    "tenantid": {
      "type": "string",
      "minLength": 1
    },
    "correlationid": {
      "type": "string",
      "minLength": 1
    },
    "aggregateversion": {
      "type": "integer",
      "minimum": 1
    },
    "data": {
      "type": "object"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "document.version.published.v1"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "document_id",
              "revision",
              "sha256",
              "previous_revision",
              "affected_object_ids"
            ],
            "properties": {
              "document_id": {
                "type": "string"
              },
              "revision": {
                "type": "integer",
                "minimum": 1
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "previous_revision": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1
              },
              "affected_object_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "question.updated.v1"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "question_id",
              "revision",
              "changed_fields",
              "reason"
            ],
            "properties": {
              "question_id": {
                "type": "string"
              },
              "revision": {
                "type": "integer",
                "minimum": 1
              },
              "changed_fields": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "string"
                }
              },
              "reason": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "certification.changed.v1"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "certification_id",
              "object_id",
              "object_revision",
              "status",
              "reason"
            ],
            "properties": {
              "certification_id": {
                "type": "string"
              },
              "object_id": {
                "type": "string"
              },
              "object_revision": {
                "type": "integer",
                "minimum": 1
              },
              "status": {
                "enum": [
                  "active",
                  "revoked",
                  "superseded"
                ]
              },
              "reason": {
                "type": "string"
              },
              "replacement_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "job.completed.v1"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "job_id",
              "result_id",
              "status",
              "usage_receipt_id"
            ],
            "properties": {
              "job_id": {
                "type": "string"
              },
              "result_id": {
                "type": "string"
              },
              "status": {
                "enum": [
                  "completed",
                  "partial"
                ]
              },
              "usage_receipt_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "analysis.ready.v1"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "analysis_id",
              "snapshot_id",
              "taxonomy_revision",
              "coverage_ratio"
            ],
            "properties": {
              "analysis_id": {
                "type": "string"
              },
              "snapshot_id": {
                "type": "string"
              },
              "taxonomy_revision": {
                "type": "integer",
                "minimum": 1
              },
              "coverage_ratio": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              }
            }
          }
        }
      }
    }
  ]
}
