{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://execkernel.org/schemas/execkernel_analytics_event_schema.json",
  "title": "Flow Analytics Event (FAE)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "sessionId",
    "timestamp",
    "flowId",
    "nodeId",
    "eventType"
  ],
  "properties": {
    "sessionId": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?![\\s\\S]*[\\u0000-\\u001f\\u007f])(?=[\\s\\S]*[^ ])"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 / ISO 8601 timestamp."
    },
    "flowId": {
      "type": "integer",
      "description": "Numeric graph identifier (deprecated graphId) derived from runtime flow_id."
    },
    "nodeId": {
      "type": "integer",
      "description": "Required for all eventType values; use the last known current_node when emitting flow_abandon."
    },
    "edgeId": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Required for edge_* events; use null or omit when the event has no edge context."
    },
    "eventType": {
      "type": "string",
      "enum": [
        "flow_start",
        "node_view",
        "edge_visible",
        "edge_selected",
        "flow_end",
        "flow_abandon"
      ]
    },
    "context": {
      "type": "object",
      "additionalProperties": true
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "label": {
          "type": "string"
        },
        "graphCode": {
          "type": "string"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "eventType": {
            "enum": [
              "edge_selected",
              "edge_visible"
            ]
          }
        }
      },
      "then": {
        "required": [
          "edgeId"
        ],
        "properties": {
          "edgeId": {
            "type": "integer"
          }
        }
      },
      "else": {
        "properties": {
          "edgeId": {
            "type": "null"
          }
        }
      }
    }
  ]
}
