{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://univip.org/schemas/v0.2/common.schema.json",
  "title": "UNIVIP common definitions v0.2",
  "description": "Enumerations are open unless marked x-univip-closed (Part 01 §1.4)",
  "$defs": {
    "DetachedJws": { "type": "string", "pattern": "^[A-Za-z0-9_-]+\\.\\.[A-Za-z0-9_-]+$", "maxLength": 2048, "description": "JWS compact serialization with detached payload (RFC 7515 Appendix F, RFC 7797): header..signature. The payload is the RFC 8785 canonical form of the signed object without its `signature` member (Part 13 §13.14)" },
    "Sha256Hex": { "type": "string", "pattern": "^[0-9a-f]{64}$", "description": "Lower-case hexadecimal SHA-256 digest" },
    "Timestamp": {
      "type": "string",
      "format": "date-time",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$",
      "description": "RFC 3339 UTC, millisecond or better precision, Z suffix required"
    },
    "DeviceId": { "type": "string", "pattern": "^[A-Za-z0-9._~:-]{1,128}$" },
    "Id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "SchemaId": { "type": "string", "pattern": "^[a-z][a-z0-9_.-]*\\.v[0-9]+\\.[0-9]+$" },
    "Latitude": { "type": "number", "minimum": -90, "maximum": 90 },
    "Longitude": { "type": "number", "minimum": -180, "maximum": 180 },
    "Degrees360": { "type": "number", "minimum": 0, "exclusiveMaximum": 360 },
    "Degrees180": { "type": "number", "minimum": -180, "maximum": 180 },
    "Percent": { "type": "number", "minimum": 0, "maximum": 100 },
    "NonNegative": { "type": "number", "minimum": 0 },
    "Position": {
      "type": "object",
      "required": ["latitude_deg", "longitude_deg"],
      "anyOf": [ { "required": ["altitude_msl_m"] }, { "required": ["altitude_ellipsoid_m"] }, { "required": ["depth_m"] } ],
      "properties": {
        "latitude_deg": { "$ref": "#/$defs/Latitude" },
        "longitude_deg": { "$ref": "#/$defs/Longitude" },
        "altitude_msl_m": { "type": "number" },
        "altitude_ellipsoid_m": { "type": "number" },
        "altitude_agl_m": { "type": "number" },
        "altitude_rel_m": { "type": "number" },
        "depth_m": { "type": "number", "minimum": 0, "description": "Depth below the water surface, positive downward (underwater and surface domains)" },
        "altitude_above_seabed_m": { "type": "number", "minimum": 0 },
        "source": { "$ref": "#/$defs/PositionSource" },
        "geoid_model": { "enum": ["EGM96", "EGM2008", "OTHER"] },
        "agl_source": { "enum": ["RANGEFINDER", "TERRAIN_MODEL", "BAROMETRIC", "ESTIMATED"] },
        "horizontal_accuracy_m": { "$ref": "#/$defs/NonNegative" },
        "age_ms": { "$ref": "#/$defs/NonNegative", "description": "Age of the fix at the sample timestamp (Part 07 §7.1)" },
        "vertical_accuracy_m": { "$ref": "#/$defs/NonNegative" }
      }
    },
    "GeoPoint": {
      "type": "object",
      "required": ["latitude_deg", "longitude_deg"],
      "properties": {
        "latitude_deg": { "$ref": "#/$defs/Latitude" },
        "longitude_deg": { "$ref": "#/$defs/Longitude" },
        "altitude_msl_m": { "type": "number" },
        "altitude_agl_m": { "type": "number" },
        "altitude_rel_m": { "type": "number" }
      }
    },
    "LocalPose": {
      "type": "object",
      "description": "Facility- or map-frame pose for indoor AMRs and GPS-denied vehicles (Part 07 §7.4.1)",
      "required": ["frame_id", "x_m", "y_m"],
      "properties": {
        "frame_id": { "$ref": "#/$defs/Id" },
        "x_m": { "type": "number" },
        "y_m": { "type": "number" },
        "z_m": { "type": "number" },
        "floor": { "type": "integer" },
        "yaw_deg": { "$ref": "#/$defs/Degrees360" },
        "source": { "$ref": "#/$defs/PositionSource" },
        "horizontal_accuracy_m": { "$ref": "#/$defs/NonNegative" },
        "age_ms": { "$ref": "#/$defs/NonNegative" }
      }
    },
    "GimbalFrame": { "enum": ["BODY", "EARTH"], "description": "BODY: yaw relative to the vehicle forward axis, pitch and roll relative to the local horizontal; EARTH: yaw relative to true north, pitch and roll relative to the local horizontal (Part 10 §10.3)" },
    "GimbalOrientation": {
      "type": "object",
      "required": ["frame"],
      "properties": {
        "frame": { "$ref": "#/$defs/GimbalFrame" },
        "roll_deg": { "$ref": "#/$defs/Degrees180" },
        "pitch_deg": { "$ref": "#/$defs/Degrees180" },
        "yaw_deg": { "type": "number", "minimum": -180, "exclusiveMaximum": 360 }
      }
    },
    "VehicleState": {
      "enum": ["OFF", "IDLE", "PREDEPLOY", "DEPLOYING", "OPERATING", "HOLDING", "RETURNING", "RECOVERING", "RECOVERED", "DOCKED", "EMERGENCY", "UNKNOWN"],
      "description": "Domain-neutral core states. Aerial reading: PREDEPLOY=preflight, DEPLOYING=taking off, OPERATING=flying, HOLDING=hovering, RETURNING=returning home, RECOVERING=landing, RECOVERED=landed. Underwater reading: DEPLOYING=launch/dive, OPERATING=submerged transit, HOLDING=station keeping, RECOVERING=surfacing/recovery."
    },
    "Domain": { "enum": ["AIR", "UNDERWATER", "SURFACE", "GROUND", "STATIONARY", "MULTI"] },
    "FormFactor": {
      "enum": [
        "MULTIROTOR", "FIXED_WING", "VTOL_HYBRID", "HELICOPTER", "TETHERED_UAV", "AEROSTAT",
        "WHEELED_AMR", "TRACKED_UGV", "LEGGED_ROBOT", "AUTONOMOUS_ROAD_VEHICLE", "RAIL_CRAWLER",
        "USV_MONOHULL", "USV_CATAMARAN", "USV_HYDROFOIL", "AUTONOMOUS_BUOY",
        "ROV_TETHERED", "AUV_TORPEDO", "UUV_HOVERING", "BENTHIC_CRAWLER",
        "DOCK_STATION", "CHARGING_PAD", "MOBILE_LAUNCH_PLATFORM", "ACOUSTIC_RELAY_BUOY",
        "OTHER"
      ]
    },
    "Propulsion": { "enum": ["ELECTRIC", "HYBRID", "COMBUSTION", "SOLAR", "TETHERED", "GLIDER", "NONE", "OTHER"] },
    "PlatformRole": { "enum": ["SURVEILLANCE", "INSPECTION", "LOGISTICS", "MAPPING", "SEARCH_RESCUE", "SECURITY_PATROL", "ENVIRONMENTAL", "RELAY", "TACTICAL_ISR", "SUPPORT", "OTHER"] },
    "AssuranceTier": { "enum": ["CIVIL", "INDUSTRIAL", "DEFENSE"] },
    "PlatformInfo": {
      "type": "object",
      "description": "Physical vehicle taxonomy, dimensions and map symbology (Part 05 §5.1.1, ADR-0011)",
      "required": ["form_factor"],
      "properties": {
        "form_factor": { "$ref": "#/$defs/FormFactor" },
        "propulsion": { "$ref": "#/$defs/Propulsion" },
        "role": { "$ref": "#/$defs/PlatformRole" },
        "dimensions_m": {
          "type": "object",
          "properties": {
            "length_m": { "type": "number", "exclusiveMinimum": 0 },
            "width_m": { "type": "number", "exclusiveMinimum": 0 },
            "height_m": { "type": "number", "exclusiveMinimum": 0 },
            "wingspan_m": { "type": "number", "exclusiveMinimum": 0 }
          }
        },
        "symbology": {
          "type": "object",
          "properties": {
            "icon": { "type": "string", "pattern": "^[a-z][a-z0-9_-]*(\\.[a-z0-9_-]+)+$", "description": "Civil map icon key, e.g. air.vtol_hybrid or ground.wheeled_amr" },
            "mil_std_2525": { "type": "string", "minLength": 15, "maxLength": 30, "description": "MIL-STD-2525D/E Symbol Identification Code (SIDC)" },
            "app6_sidc": { "type": "string", "minLength": 15, "maxLength": 30, "description": "NATO APP-6 Symbol Identification Code" },
            "color_hint": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" }
          }
        }
      }
    },
    "PositionSource": { "enum": ["GNSS", "RTK_GNSS", "USBL", "LBL", "DVL_INS", "VISUAL_INS", "LIDAR_SLAM", "WHEEL_ODOMETRY", "UWB", "FIDUCIAL", "DEAD_RECKONING", "SURFACE_GNSS_LAST_FIX", "UNKNOWN"] },
    "GnssFix": { "enum": ["NONE", "2D", "3D", "DGPS", "RTK_FLOAT", "RTK_FIXED", "UNKNOWN"] },
    "LinkState": { "enum": ["CONNECTED", "DEGRADED", "LOST", "UNKNOWN"] },
    "HealthStatus": { "enum": ["OK", "WARNING", "ERROR", "UNKNOWN"] },
    "Severity": { "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] },
    "TimeSource": { "enum": ["GNSS", "NTP", "PTP", "FREE_RUNNING", "UNKNOWN"] },
    "ImplementationMode": { "enum": ["NATIVE", "CONTROLLER", "GATEWAY"] },
    "Profile": { "enum": ["T", "S", "C", "N", "A", "F"] },
    "PayloadType": { "enum": ["CAMERA", "THERMAL", "DUAL_EO_IR", "MULTISPECTRAL", "LIDAR", "RANGEFINDER", "SENSOR", "SONAR", "ENVIRONMENTAL", "SPOTLIGHT", "SPEAKER", "OTHER"] },
    "CommandType": {
      "type": "string",
      "pattern": "^((camera|vehicle|payload)\\.[a-z_]+(\\.[a-z_]+)*|[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+\\.[a-z_]+)$",
      "description": "Standard family (camera., vehicle., payload.) or reverse-DNS vendor command"
    },
    "CommandState": { "enum": ["ACCEPTED", "REJECTED", "QUEUED", "EXECUTING", "COMPLETED", "FAILED", "CANCELLED", "SUPERSEDED"], "x-univip-closed": true },
    "Reason": {
      "enum": ["UNSUPPORTED_COMMAND", "INVALID_PARAMETERS", "NO_LEASE", "LEASE_SCOPE", "LEASE_EXPIRED", "OUT_OF_LIMITS", "PAYLOAD_UNAVAILABLE", "BUSY", "FLIGHT_STATE", "PILOT_OVERRIDE", "GEOFENCE", "SAFETY", "FLIGHT_CONTROL_DISABLED", "LINK_LOST", "EXPIRED", "ODD_OUT_OF_BOUNDS", "INTERVENTION_REQUIRED", "CORRIDOR_CONFLICT", "ESTOP_ACTIVE", "INTERNAL"]
    },
    "LeaseScope": { "type": "string", "pattern": "^(vehicle|autonomy|camera:\\*|camera:[A-Za-z0-9._~-]{1,64})$" },
    "LeaseState": { "enum": ["PENDING", "ACTIVE", "RELEASED", "EXPIRED", "REVOKED", "PREEMPTED"], "x-univip-closed": true },
    "Identity": {
      "type": "object",
      "required": ["device_id", "manufacturer", "model", "univip_version", "implementation_mode", "domain"],
      "properties": {
        "device_id": { "$ref": "#/$defs/DeviceId" },
        "manufacturer": { "type": "string" },
        "model": { "type": "string" },
        "serial_number": { "type": "string" },
        "firmware_version": { "type": "string" },
        "univip_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+" },
        "implementation_mode": { "$ref": "#/$defs/ImplementationMode" },
        "domain": { "$ref": "#/$defs/Domain" },
        "platform": { "$ref": "#/$defs/PlatformInfo" },
        "remote_id": {
          "type": "object",
          "properties": { "serial": { "type": "string" }, "session_id": { "type": "string" } }
        },
        "gateway": {
          "type": "object",
          "properties": {
            "vendor": { "type": "string" }, "product": { "type": "string" },
            "version": { "type": "string" }, "adapter": { "type": "string" }
          }
        }
      }
    },
    "GeoJSONPolygon": {
      "type": "object",
      "required": ["type", "coordinates"],
      "properties": {
        "type": { "const": "Polygon" },
        "coordinates": {
          "type": "array", "minItems": 1,
          "items": {
            "type": "array", "minItems": 4,
            "items": { "type": "array", "minItems": 2, "maxItems": 3, "items": { "type": "number" } }
          }
        }
      }
    },
    "GeoJSONMultiPolygon": {
      "type": "object",
      "required": ["type", "coordinates"],
      "properties": {
        "type": { "const": "MultiPolygon" },
        "coordinates": {
          "type": "array",
          "items": { "$ref": "#/$defs/GeoJSONPolygon/properties/coordinates" }
        }
      }
    }
  }
}
