{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://univip.org/schemas/v0.2/capabilities.schema.json",
  "title": "UNIVIP capability document v0.2",
  "type": "object",
  "required": ["schema", "device", "profiles", "schemas", "transports", "telemetry", "events", "media"],
  "properties": {
    "schema": { "type": "string", "pattern": "^univip\\.capabilities\\.v0\\.[0-9]+$", "description": "Any 0.x MINOR is accepted (Part 01 §1.5)" },
    "device": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Identity" },
    "profiles": { "type": "array", "uniqueItems": true, "items": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Profile" } },
    "schemas": { "type": "array", "minItems": 1, "items": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/SchemaId" } },
    "transports": {
      "type": "object",
      "required": ["rest", "realtime", "media"],
      "properties": {
        "rest": {
          "type": "object",
          "required": ["device_hosted"],
          "properties": {
            "device_hosted": { "type": "boolean" },
            "base_url": { "type": "string", "format": "uri" },
            "session_proxy": { "type": "boolean", "description": "The device answers request envelopes on the session channel (Part 05 §5.5.1)" },
            "insecure": { "type": "boolean", "description": "base_url is plaintext HTTP (isolated local link only, Part 13 §13.2)" }
          },
          "if": { "properties": { "device_hosted": { "const": true } } },
          "then": { "required": ["base_url"] }
        },
        "realtime": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "enum": ["WSS", "MQTT5", "QUIC"] } },
        "media": { "type": "array", "uniqueItems": true, "items": { "enum": ["WEBRTC", "RTSP", "SRT"] }, "description": "Non-empty whenever a profile is claimed" }
      }
    },
    "telemetry": {
      "type": "object",
      "required": ["rate_hz", "fields"],
      "properties": {
        "rate_hz": {
          "type": "object",
          "required": ["min", "max", "default"],
          "properties": {
            "min": { "type": "number", "exclusiveMinimum": 0 },
            "max": { "type": "number", "exclusiveMinimum": 0 },
            "default": { "type": "number", "exclusiveMinimum": 0 }
          }
        },
        "applied_rate_hz": { "type": "number", "exclusiveMinimum": 0, "description": "Rate currently applied for this session after clamping (Part 05 §5.4.2)" },
        "fields": { "type": "array", "items": { "enum": ["position", "local_pose", "motion", "power", "link", "vehicle", "payloads", "health", "autonomy", "fleet"] } },
        "store_and_forward": { "type": "boolean", "description": "Offline samples are buffered and delivered with replayed: true on reconnect (Part 07 §7.11)" }
      }
    },
    "events": {
      "type": "object",
      "required": ["topics"],
      "properties": { "topics": { "type": "array", "items": { "type": "string", "pattern": "^[a-z][a-z0-9_-]*(\\.[a-z0-9_-]+)+$" } } }
    },
    "media": {
      "type": "object",
      "required": ["streams"],
      "properties": {
        "streams": { "type": "array", "items": { "$ref": "#/$defs/StreamDescriptor" } },
        "webrtc": {
          "type": "object",
          "properties": {
            "ice": { "enum": ["FULL", "LITE"], "description": "LITE: host candidates only; usable only where the client can reach them (Part 09 §9.3)" }
          }
        }
      }
    },
    "payloads": { "type": "array", "items": { "$ref": "#/$defs/PayloadCapability" } },
    "vehicle": { "$ref": "#/$defs/VehicleCapability" },
    "autonomy": { "$ref": "#/$defs/AutonomyCapability" },
    "fleet": { "$ref": "#/$defs/FleetCapability" },
    "geospatial": {
      "type": "object",
      "required": ["supported"],
      "properties": { "supported": { "type": "boolean" }, "fields": { "type": "array", "items": { "type": "string" } } }
    },
    "extensions": { "type": "array", "items": { "type": "string" } },
    "security": {
      "type": "object",
      "description": "Device security posture and assurance tier (Part 13 §13.12-13.21, ADR-0011). An absent member means the device makes no claim.",
      "properties": {
        "assurance_tier": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/AssuranceTier", "description": "CIVIL (Tier 1), INDUSTRIAL (Tier 2), or DEFENSE (Tier 3)" },
        "key_storage": { "enum": ["SECURE_ELEMENT", "TPM", "TEE", "SOFTWARE", "UNKNOWN"], "description": "Where the device credential private key lives" },
        "attestation": { "type": "boolean", "description": "The device can present an EAT attestation (§13.12)" },
        "secure_boot": { "type": "boolean" },
        "signed_firmware": { "type": "boolean", "description": "Accepts only signed firmware with anti-rollback (§13.13)" },
        "signed_commands": { "type": "boolean", "description": "Requires a valid `signature` on vehicle commands (§13.14)" },
        "dual_control": { "type": "boolean", "description": "Requires M-of-N `signatures[]` on high-consequence commands (Tier 3, §13.21)" },
        "post_quantum": { "type": "boolean", "description": "Enforces post-quantum hybrid KEX and/or PQ command/audit signatures (Tier 3, §13.21)" },
        "audit_chain": { "type": "boolean", "description": "Audit records carry prev_hash and signed checkpoints are delivered (§13.15)" },
        "wire_encodings": { "type": "array", "uniqueItems": true, "items": { "enum": ["JSON", "CBOR", "PROTOBUF"] }, "description": "Supported session/command wire encodings" },
        "emcon_supported": { "type": "boolean", "description": "Supports radio-silence (EMCON) receive-only / burst sync operation (§13.21)" }
      }
    }
  },
  "allOf": [
    { "if": { "properties": { "profiles": { "contains": { "const": "S" } } }, "required": ["profiles"] },
      "then": { "properties": {
        "transports": { "properties": { "media": { "minItems": 1 } } },
        "media": { "properties": { "streams": { "minItems": 1 } } }
      } } },
    { "if": { "properties": { "profiles": { "contains": { "const": "C" } } }, "required": ["profiles"] },
      "then": { "required": ["payloads"], "properties": { "profiles": { "contains": { "const": "S" } } } } },
    { "if": { "properties": { "profiles": { "contains": { "const": "N" } } }, "required": ["profiles"] },
      "then": { "required": ["vehicle"], "properties": { "profiles": {
        "anyOf": [ { "contains": { "const": "T" } }, { "contains": { "const": "S" } } ]
      } } } },
    { "if": { "properties": { "profiles": { "contains": { "const": "A" } } }, "required": ["profiles"] },
      "then": { "required": ["autonomy"], "properties": { "profiles": { "contains": { "const": "N" } } } } },
    { "if": { "properties": { "profiles": { "contains": { "const": "F" } } }, "required": ["profiles"] },
      "then": { "required": ["fleet"], "properties": { "profiles": {
        "anyOf": [ { "contains": { "const": "T" } }, { "contains": { "const": "S" } } ]
      } } } },
    { "$comment": "0.2 (Part 05 §5.5.1): a device that does not host REST must offer the session proxy; 0.1 documents are exempt (Part 01 §1.5)",
      "if": { "properties": { "schema": { "pattern": "^univip\\.capabilities\\.v0\\.([2-9]|[1-9][0-9]+)$" },
                              "transports": { "properties": { "rest": { "properties": { "device_hosted": { "const": false } }, "required": ["device_hosted"] } } } },
              "required": ["schema", "transports"] },
      "then": { "properties": { "transports": { "properties": { "rest": { "required": ["session_proxy"], "properties": { "session_proxy": { "const": true } } } } } } } }
  ],
  "$defs": {
    "StreamDescriptor": {
      "type": "object",
      "required": ["stream_id", "kind", "codecs", "transports"],
      "properties": {
        "stream_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id" },
        "payload_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id" },
        "name": { "type": "string" },
        "kind": { "enum": ["VIDEO", "AUDIO"] },
        "codecs": { "type": "array", "minItems": 1, "items": { "enum": ["H264", "H265", "VP8", "AV1", "OPUS"] } },
        "h264": {
          "type": "object",
          "properties": {
            "profiles": { "type": "array", "items": { "enum": ["CONSTRAINED_BASELINE", "BASELINE", "MAIN", "HIGH"] } },
            "max_level": { "type": "string" }
          }
        },
        "resolutions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["width", "height", "max_fps"],
            "properties": {
              "width": { "type": "integer", "minimum": 1 },
              "height": { "type": "integer", "minimum": 1 },
              "max_fps": { "type": "number", "exclusiveMinimum": 0 }
            }
          }
        },
        "max_bitrate_kbps": { "type": "number", "exclusiveMinimum": 0 },
        "audio": { "type": "boolean" },
        "transports": { "type": "array", "minItems": 1, "items": { "enum": ["WEBRTC", "RTSP", "SRT"] } },
        "rtsp": { "type": ["object", "null"], "properties": { "url": { "type": "string" }, "insecure": { "type": "boolean" } } },
        "srt": { "type": ["object", "null"], "properties": { "url": { "type": "string" }, "mode": { "enum": ["CALLER", "LISTENER"] }, "encryption": { "enum": ["AES128", "AES256"] } } },
        "in_band_metadata": { "type": "array", "items": { "enum": ["MISB_0601", "ONVIF_METADATA"] } },
        "latency_class": { "enum": ["INTERACTIVE", "LOW", "CONTRIBUTION"] }
      }
    },
    "Range": {
      "type": "object",
      "required": ["min", "max"],
      "properties": { "min": { "type": "number" }, "max": { "type": "number" } }
    },
    "PayloadCapability": {
      "type": "object",
      "required": ["payload_id", "type", "lease_required"],
      "properties": {
        "payload_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id" },
        "type": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/PayloadType" },
        "name": { "type": "string" },
        "lease_required": { "type": "boolean" },
        "lease": {
          "type": "object",
          "description": "Camera lease parameters when lease_required is true (Part 11 §11.3)",
          "required": ["max_ttl_s", "heartbeat_interval_s"],
          "properties": {
            "max_ttl_s": { "type": "number", "exclusiveMinimum": 0, "maximum": 3600 },
            "heartbeat_interval_s": { "type": "number", "exclusiveMinimum": 0, "maximum": 60 }
          }
        },
        "gimbal": {
          "type": ["object", "null"],
          "required": ["axes", "frames"],
          "properties": {
            "axes": { "type": "array", "items": { "enum": ["ROLL", "PITCH", "YAW"] } },
            "frames": { "type": "array", "minItems": 1, "items": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/GimbalFrame" } },
            "limits_deg": {
              "type": "object",
              "properties": { "roll": { "$ref": "#/$defs/Range" }, "pitch": { "$ref": "#/$defs/Range" }, "yaw": { "$ref": "#/$defs/Range" } }
            },
            "max_rate_degps": {
              "type": "object",
              "properties": { "roll": { "type": "number" }, "pitch": { "type": "number" }, "yaw": { "type": "number" } }
            },
            "continuous_move": { "type": "boolean" }
          }
        },
        "zoom": {
          "type": ["object", "null"],
          "required": ["min_ratio", "max_ratio"],
          "properties": {
            "min_ratio": { "type": "number", "exclusiveMinimum": 0 },
            "max_ratio": { "type": "number", "exclusiveMinimum": 0 },
            "optical_max_ratio": { "type": "number", "exclusiveMinimum": 0 },
            "continuous": { "type": "boolean" }
          }
        },
        "focus": { "type": ["object", "null"], "properties": { "modes": { "type": "array", "items": { "enum": ["AUTO", "MANUAL", "ONE_SHOT"] } } } },
        "imaging": { "type": ["object", "null"], "properties": { "parameters": { "type": "array", "items": { "type": "string" } } } },
        "thermal": {
          "type": ["object", "null"],
          "properties": {
            "palettes": { "type": "array", "items": { "type": "string" } },
            "gain_modes": { "type": "array", "items": { "type": "string" } },
            "radiometric": { "type": "boolean" }
          }
        },
        "recording": { "type": ["object", "null"], "properties": { "supported": { "type": "boolean" }, "local_storage": { "type": "boolean" } } },
        "snapshot": { "type": ["object", "null"], "properties": { "supported": { "type": "boolean" } } },
        "spotlight": { "type": ["object", "null"] },
        "speaker": { "type": ["object", "null"] }
      }
    },
    "VehicleCapability": {
      "type": "object",
      "required": ["enabled", "domain", "commands", "limits", "lease", "operator_authority"],
      "properties": {
        "enabled": { "type": "boolean" },
        "domain": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Domain" },
        "commands": {
          "type": "array",
          "allOf": [
            { "contains": { "const": "vehicle.hold" } },
            { "contains": { "const": "vehicle.return_home" } },
            { "contains": { "const": "vehicle.cancel" } }
          ],
          "items": { "type": "string", "pattern": "^vehicle\\.[a-z_]+(\\.[a-z_]+)*$" }
        },
        "limits": {
          "type": "object",
          "properties": {
            "max_altitude_agl_m": { "type": ["number", "null"] },
            "max_altitude_msl_m": { "type": ["number", "null"] },
            "max_distance_from_home_m": { "type": ["number", "null"] },
            "max_ground_speed_mps": { "type": ["number", "null"] },
            "max_depth_m": { "type": ["number", "null"] },
            "min_altitude_above_seabed_m": { "type": ["number", "null"] },
            "altitude_agl_basis": { "enum": ["TERRAIN_MODEL", "RANGEFINDER", "HOME_ELEVATION"], "description": "How the device evaluates max_altitude_agl_m (Part 11 §11.2)" },
            "geofence": {
              "anyOf": [
                { "type": "null" },
                { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/GeoJSONPolygon" },
                { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/GeoJSONMultiPolygon" }
              ]
            }
          }
        },
        "lease": {
          "type": "object",
          "required": ["max_ttl_s", "heartbeat_interval_s"],
          "properties": {
            "max_ttl_s": { "type": "number", "exclusiveMinimum": 0, "maximum": 3600 },
            "heartbeat_interval_s": { "type": "number", "exclusiveMinimum": 0, "maximum": 60 },
            "preemptable_by": { "type": "array", "items": { "enum": ["PILOT", "OPERATOR_POLICY", "HIGHER_PRIORITY_CLIENT"] } }
          }
        },
        "missions": {
          "type": "object",
          "properties": {
            "formats": { "type": "array", "items": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/SchemaId" } },
            "max_waypoints": { "type": "integer", "minimum": 1 }
          }
        },
        "operator_authority": {
          "type": "object",
          "required": ["pilot_override"],
          "properties": {
            "pilot_present_required": { "type": "boolean" },
            "pilot_override": { "const": "ALWAYS" }
          }
        }
      }
    },
    "AutonomyCapability": {
      "type": "object",
      "description": "Profile A capability declaration (Part 15 §15.2.1)",
      "required": ["enabled", "goal_types", "session_loss_policies"],
      "properties": {
        "enabled": { "type": "boolean" },
        "goal_types": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "session_loss_policies": {
          "type": "array",
          "minItems": 1,
          "contains": { "const": "HOLD" },
          "items": { "enum": ["HOLD", "CONTINUE_WITHIN_ODD", "RETURN_HOME", "SAFE_STOP"] }
        },
        "max_offline_grace_s": { "type": "number", "minimum": 0 },
        "human_assist": { "type": "boolean" },
        "odd_monitoring": { "type": "boolean" },
        "perception_stream": { "type": "boolean" }
      },
      "if": { "properties": { "session_loss_policies": { "contains": { "const": "CONTINUE_WITHIN_ODD" } } }, "required": ["session_loss_policies"] },
      "then": { "required": ["max_offline_grace_s"] }
    },
    "FleetCapability": {
      "type": "object",
      "description": "Profile F capability declaration (Part 15 §15.3.1)",
      "properties": {
        "fleet_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id" },
        "dock_supported": { "type": "boolean" },
        "dynamic_corridors": { "type": "boolean" },
        "handoff_roles": { "type": "array", "items": { "enum": ["PRIMARY", "RELIEF"] } },
        "commands": { "type": "array", "items": { "type": "string", "pattern": "^vehicle\\.(dock|fleet)\\.[a-z_]+$" } }
      }
    }
  }
}
