{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rage.fail/schemas/0.1/edge.schema.json",
  "title": "RAGE Edge",
  "type": "object",
  "required": [
    "kind",
    "source",
    "target",
    "type"
  ],
  "additionalProperties": true,
  "properties": {
    "kind": {
      "const": "edge"
    },
    "type": {
      "type": "string"
    },
    "source": {
      "type": "string"
    },
    "target": {
      "type": "string"
    },
    "edge_id": {
      "type": "string",
      "description": "Stable id for this edge. SHOULD be present so paths/facts can reference it. When derived deterministically it is `e_` + first 16 hex chars of sha256(\"<type>|<source>|<target>|<scope>\"). MUST be unique within a graph when present."
    },
    "scope": {
      "type": "string",
      "description": "the realm the edge applies in (e.g. a resource ARN/id); part of the deterministic edge_id key"
    },
    "provider": {
      "type": "string"
    },
    "nature": {
      "enum": [
        "explicit",
        "derived"
      ],
      "default": "explicit",
      "description": "explicit = observed directly from configuration; derived = synthesized by a rule. Default explicit."
    },
    "state": {
      "enum": [
        "ACTIVE",
        "CONDITIONAL",
        "POTENTIAL",
        "BLOCKED",
        "UNKNOWN"
      ],
      "default": "ACTIVE"
    },
    "confidence": {
      "type": "number"
    },
    "weight": {
      "type": "number"
    },
    "conditions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "rule_id": {
      "type": "string",
      "description": "for derived edges: the rules/ id that produced this edge"
    },
    "derived_from": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "for derived edges: the edge_ids this edge was composed from"
    },
    "observed_at": {
      "type": "string",
      "format": "date-time",
      "description": "when the underlying data was collected"
    },
    "evidence": {},
    "facts": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "fact_ids that justify this edge"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "nature": {
            "const": "derived"
          }
        },
        "required": [
          "nature"
        ]
      },
      "then": {
        "required": [
          "evidence"
        ]
      }
    }
  ]
}