{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nodedc.ru/schemas/map-scene-fixture-v0.1.schema.json",
  "title": "NODE.DC Map Scene Fixture v0.1",
  "description": "Provider-neutral acceptance scene for the canonical Map Page Template.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "fixtureId", "template", "title", "state", "viewport", "capabilities", "styleProfiles", "scene", "selection", "acceptance"],
  "properties": {
    "schemaVersion": { "const": "0.1.0" },
    "fixtureId": { "$ref": "#/$defs/id" },
    "template": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version"],
      "properties": {
        "id": { "const": "map" },
        "version": { "const": "0.1.0" }
      }
    },
    "title": { "type": "string", "minLength": 1, "maxLength": 120 },
    "description": { "type": "string", "maxLength": 500 },
    "state": { "enum": ["ready", "loading", "empty", "stale", "error", "offline"] },
    "viewport": {
      "type": "object",
      "additionalProperties": false,
      "required": ["center", "heading", "pitch", "range"],
      "properties": {
        "center": { "$ref": "#/$defs/position" },
        "heading": { "type": "number", "minimum": 0, "maximum": 360 },
        "pitch": { "type": "number", "minimum": -90, "maximum": 90 },
        "range": { "type": "number", "exclusiveMinimum": 0 }
      }
    },
    "capabilities": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": ["camera", "base-layer", "buildings", "grid", "labels", "pins", "moving-objects", "traces", "routes", "tracks", "stations", "zones", "selection"]
      }
    },
    "styleProfiles": {
      "type": "array",
      "items": { "$ref": "#/$defs/styleProfile" }
    },
    "scene": {
      "type": "object",
      "additionalProperties": false,
      "required": ["layers", "places", "movingObjects", "stations", "routes", "tracks", "zones"],
      "properties": {
        "layers": { "type": "array", "items": { "$ref": "#/$defs/layer" } },
        "places": { "type": "array", "items": { "$ref": "#/$defs/place" } },
        "movingObjects": { "type": "array", "items": { "$ref": "#/$defs/movingObject" } },
        "stations": { "type": "array", "items": { "$ref": "#/$defs/station" } },
        "routes": { "type": "array", "items": { "$ref": "#/$defs/linearEntity" } },
        "tracks": { "type": "array", "items": { "$ref": "#/$defs/linearEntity" } },
        "zones": { "type": "array", "items": { "$ref": "#/$defs/zone" } }
      }
    },
    "selection": {
      "type": "object",
      "additionalProperties": false,
      "required": ["entityId"],
      "properties": {
        "entityId": { "type": ["string", "null"] }
      }
    },
    "acceptance": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "expect"],
        "properties": {
          "id": { "$ref": "#/$defs/id" },
          "expect": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
        }
      }
    }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)*$" },
    "position": {
      "type": "array",
      "minItems": 2,
      "maxItems": 3,
      "prefixItems": [
        { "type": "number", "minimum": -180, "maximum": 180 },
        { "type": "number", "minimum": -90, "maximum": 90 },
        { "type": "number" }
      ]
    },
    "styleProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "variant"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "kind": { "enum": ["layer", "grid", "label", "pin", "line", "fill"] },
        "variant": { "type": "string", "minLength": 1 },
        "color": { "type": "string", "pattern": "^#[0-9a-fA-F]{6}$" },
        "opacity": { "type": "number", "minimum": 0, "maximum": 1 },
        "width": { "type": "number", "exclusiveMinimum": 0 },
        "size": { "type": "number", "exclusiveMinimum": 0 },
        "pinPresentation": { "$ref": "#/$defs/pinPresentation" }
      }
    },
    "pinPresentation": {
      "type": "object",
      "description": "Provider-neutral elevated-spike presentation for a map.pin. A renderer adapter maps these values to its own primitives.",
      "additionalProperties": false,
      "required": ["variant", "stemHeightMeters", "headSizePx", "stemWidthPx", "outlineColor", "outlineOpacity", "outlineWidthPx", "labelOffsetX", "labelOffsetY"],
      "properties": {
        "variant": { "enum": ["elevated-spike"] },
        "stemHeightMeters": { "type": "number", "minimum": 0 },
        "headSizePx": { "type": "number", "exclusiveMinimum": 0 },
        "stemWidthPx": { "type": "number", "exclusiveMinimum": 0 },
        "outlineColor": { "type": "string", "pattern": "^#[0-9a-fA-F]{6}$" },
        "outlineOpacity": { "type": "number", "minimum": 0, "maximum": 1 },
        "outlineWidthPx": { "type": "number", "minimum": 0 },
        "labelOffsetX": { "type": "number" },
        "labelOffsetY": { "type": "number" },
        "pinHideCameraHeightMeters": { "type": "number", "exclusiveMinimum": 0 },
        "labelHideCameraHeightMeters": { "type": "number", "exclusiveMinimum": 0 }
      }
    },
    "visibility": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minRange", "maxRange"],
      "properties": {
        "minRange": { "type": "number", "minimum": 0 },
        "maxRange": { "type": "number", "exclusiveMinimum": 0 }
      }
    },
    "label": {
      "type": "object",
      "additionalProperties": false,
      "required": ["text", "styleProfileId"],
      "properties": {
        "text": { "type": "string", "minLength": 1 },
        "styleProfileId": { "$ref": "#/$defs/id" }
      }
    },
    "layer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "visible", "styleProfileId"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "type": { "enum": ["base", "buildings", "grid"] },
        "visible": { "type": "boolean" },
        "mode": { "enum": ["surface", "volume", "graticule"] },
        "styleProfileId": { "$ref": "#/$defs/id" },
        "visibility": { "$ref": "#/$defs/visibility" },
        "lodLevels": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["level", "minRange", "maxRange"],
            "properties": {
              "level": { "type": "integer", "minimum": 0 },
              "minRange": { "type": "number", "minimum": 0 },
              "maxRange": { "type": "number", "exclusiveMinimum": 0 }
            }
          }
        }
      }
    },
    "place": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name", "position", "label", "visibility"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "name": { "type": "string", "minLength": 1 },
        "position": { "$ref": "#/$defs/position" },
        "label": { "$ref": "#/$defs/label" },
        "visibility": { "$ref": "#/$defs/visibility" }
      }
    },
    "movingObject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "objectType", "status", "position", "heading", "pinStyleProfileId", "label"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "objectType": { "enum": ["rail", "metro", "tram", "bus", "vehicle", "drone", "generic"] },
        "status": { "enum": ["active", "idle", "delayed", "warning", "offline", "unknown"] },
        "position": { "$ref": "#/$defs/position" },
        "heading": { "type": "number", "minimum": 0, "maximum": 360 },
        "pinStyleProfileId": { "$ref": "#/$defs/id" },
        "label": { "$ref": "#/$defs/label" },
        "trace": { "type": "array", "minItems": 2, "items": { "$ref": "#/$defs/position" } }
      }
    },
    "station": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "stationType", "position", "pinStyleProfileId", "label"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "stationType": { "enum": ["rail", "metro", "stop", "terminal", "generic"] },
        "position": { "$ref": "#/$defs/position" },
        "pinStyleProfileId": { "$ref": "#/$defs/id" },
        "label": { "$ref": "#/$defs/label" }
      }
    },
    "linearEntity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "coordinates", "styleProfileId"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "coordinates": { "type": "array", "minItems": 2, "items": { "$ref": "#/$defs/position" } },
        "styleProfileId": { "$ref": "#/$defs/id" },
        "label": { "$ref": "#/$defs/label" }
      }
    },
    "zone": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "geometry", "styleProfileId", "label"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "geometry": {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "coordinates"],
          "properties": {
            "type": { "enum": ["Polygon", "MultiPolygon"] },
            "coordinates": { "type": "array", "minItems": 1 }
          }
        },
        "styleProfileId": { "$ref": "#/$defs/id" },
        "label": { "$ref": "#/$defs/label" }
      }
    }
  }
}
