{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://ziggyserver.ru/layerplan/spec/route-snapshot.schema.json",
  "title": "RouteSnapshot",
  "description": "Выход L2 Routing. Состояние всех маршрутов и загрузки путей.",
  "type": "object",
  "required": ["routes", "congestion"],
  "properties": {
    "routes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["vehicle_id", "path", "status"],
        "properties": {
          "vehicle_id": { "type": "string" },
          "path": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Упорядоченный список node_id от начальной до конечной станции"
          },
          "status": {
            "type": "string",
            "enum": ["active", "waiting", "deadlocked"]
          },
          "progress": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Прогресс по текущему сегменту 0–1"
          },
          "waiting_since_tick": {
            "type": "integer",
            "description": "С какого тика маршрут в статусе waiting/deadlocked"
          }
        }
      }
    },
    "congestion": {
      "type": "object",
      "patternProperties": {
        "^[a-f0-9\\-]{36}$": {
          "type": "object",
          "properties": {
            "edge_id": { "type": "string" },
            "utilization_pct": { "type": "number", "minimum": 0, "maximum": 100 },
            "vehicles_current": { "type": "integer", "minimum": 0 },
            "capacity": { "type": "integer", "minimum": 1 }
          }
        }
      },
      "description": "Загрузка каждого ребра графа. Ключ: edge_id."
    },
    "bottlenecks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "node_id": { "type": "string" },
          "utilization_pct": { "type": "number", "minimum": 0, "maximum": 100 },
          "waiting_vehicles": { "type": "integer", "minimum": 0 }
        }
      },
      "description": "Узлы с загрузкой > 80%"
    },
    "deadlock_info": {
      "type": "object",
      "properties": {
        "deadlocked_vehicles": {
          "type": "array",
          "items": { "type": "string" },
          "description": "ID машин в deadlock"
        },
        "cycle": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Цикл ожидания: [A_ждёт_B, B_ждёт_C, C_ждёт_A]"
        },
        "resolution_ticks": {
          "type": "integer",
          "description": "Сколько тиков потребовалось на разрешение"
        }
      }
    }
  }
}
