{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://architectonic.dev/schemas/skills-navigation.schema.json",
  "title": "Architectonic Skills Navigation Graph",
  "type": "object",
  "required": [
    "schema_version",
    "source_repo",
    "source_ref",
    "summary",
    "nodes",
    "edges"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "0.1"
    },
    "source_repo": {
      "type": "string",
      "minLength": 1
    },
    "source_ref": {
      "type": "string",
      "minLength": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "node_count",
        "leaf_count",
        "browse_default_visible",
        "browse_default_hidden",
        "edge_count"
      ],
      "properties": {
        "node_count": { "type": "integer", "minimum": 0 },
        "leaf_count": { "type": "integer", "minimum": 0 },
        "browse_default_visible": { "type": "integer", "minimum": 0 },
        "browse_default_hidden": { "type": "integer", "minimum": 0 },
        "edge_count": { "type": "integer", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "nodes": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/node" }
    },
    "edges": {
      "type": "array",
      "items": { "$ref": "#/$defs/edge" }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "nodeKind": {
      "type": "string",
      "enum": ["root", "section", "group", "pack", "category", "leaf"]
    },
    "leafRef": {
      "type": "object",
      "required": ["source_repo", "source_path"],
      "properties": {
        "source_repo": { "type": "string", "minLength": 1 },
        "source_path": { "type": "string", "minLength": 1 },
        "slug": { "type": "string" }
      },
      "additionalProperties": false
    },
    "node": {
      "type": "object",
      "required": ["id", "kind", "title"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "kind": { "$ref": "#/$defs/nodeKind" },
        "title": { "type": "string", "minLength": 1 },
        "description": { "type": "string" },
        "children": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "browse_default": { "type": "boolean" },
        "ref": { "$ref": "#/$defs/leafRef" }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "leaf" } } },
          "then": {
            "required": ["ref", "browse_default"],
            "not": { "required": ["children"] }
          }
        },
        {
          "if": {
            "properties": {
              "kind": { "enum": ["root", "section", "group", "pack", "category"] }
            }
          },
          "then": { "required": ["children"] }
        }
      ],
      "additionalProperties": false
    },
    "edge": {
      "type": "object",
      "required": ["from", "to", "kind"],
      "properties": {
        "from": { "type": "string", "minLength": 1 },
        "to": { "type": "string", "minLength": 1 },
        "kind": {
          "type": "string",
          "enum": ["superseded_by"]
        }
      },
      "additionalProperties": false
    }
  }
}
