{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://enygnadev.github.io/pnva-core/schemas/pnva-event.schema.json",
  "title": "PNVA Event Envelope",
  "description": "Canonical log envelope for PNVA-Core event, tension, collapse and proof records.",
  "type": "object",
  "required": [
    "schema_version",
    "event_id",
    "timestamp",
    "causal_chain_id",
    "entity_id",
    "event_type",
    "field",
    "tension",
    "decision",
    "proof"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "pnva.event.v1"
    },
    "event_id": {
      "type": "string",
      "minLength": 6,
      "maxLength": 160
    },
    "timestamp": {
      "type": "string"
    },
    "causal_chain_id": {
      "type": "string",
      "minLength": 3,
      "maxLength": 160
    },
    "entity_id": {
      "type": "string",
      "minLength": 3,
      "maxLength": 128
    },
    "entity_type": {
      "type": "string"
    },
    "event_type": {
      "type": "string"
    },
    "field": {
      "type": "object",
      "required": [
        "state_before",
        "state_after"
      ],
      "properties": {
        "state_before": {
          "type": "string"
        },
        "state_after": {
          "type": "string"
        },
        "phi": {
          "type": "number"
        },
        "gradient": {
          "type": "number"
        },
        "hessian": {
          "type": "number"
        }
      },
      "additionalProperties": true
    },
    "tension": {
      "type": "object",
      "required": [
        "score",
        "threshold",
        "gate_delta"
      ],
      "properties": {
        "score": {
          "type": "number"
        },
        "threshold": {
          "type": "number"
        },
        "margin": {
          "type": "number"
        },
        "gate_delta": {
          "type": "number"
        },
        "components": {
          "type": "object"
        }
      },
      "additionalProperties": true
    },
    "decision": {
      "type": "object",
      "required": [
        "kind",
        "action",
        "reason"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "collapse",
            "block",
            "observe",
            "reclassify",
            "prove"
          ]
        },
        "action": {
          "type": "string"
        },
        "reason": {
          "type": "string"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "additionalProperties": true
    },
    "heuristics": {
      "type": "object",
      "properties": {
        "rules": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "risk_flags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": true
    },
    "proof": {
      "type": "object",
      "required": [
        "proof_hash",
        "proof_ref",
        "valid"
      ],
      "properties": {
        "proof_hash": {
          "type": "string"
        },
        "proof_ref": {
          "type": "string"
        },
        "valid": {
          "type": "boolean"
        },
        "canonical": {
          "type": "boolean"
        },
        "native": {
          "type": "boolean"
        }
      },
      "additionalProperties": true
    },
    "source": {
      "type": "object",
      "properties": {
        "format": {
          "type": "string"
        },
        "file_name": {
          "type": "string"
        },
        "line": {
          "type": "integer"
        },
        "sanitized": {
          "type": "boolean"
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
