{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://quadruper.invalid/contracts/geoapi-traffic-response.v1.schema.json",
  "title": "TrafficResponse",
  "description": "GET /v2/traffic 200 body: active stretches, marked by staff or derived from our taxis' GPS. Route times don't use them yet.",
  "type": "object",
  "properties": {
    "type": { "const": "FeatureCollection" },
    "features": {
      "type": "array",
      "maxItems": 500,
      "items": {
        "title": "TrafficFeature",
        "type": "object",
        "properties": {
          "type": { "const": "Feature" },
          "id": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
          "geometry": {
            "title": "LineString",
            "description": "In the direction of travel.",
            "type": "object",
            "properties": {
              "type": { "const": "LineString" },
              "coordinates": { "type": "array", "minItems": 2, "items": { "$ref": "geoapi-common.v1.schema.json#/$defs/lnglat" } }
            },
            "required": ["type", "coordinates"],
            "additionalProperties": false
          },
          "properties": {
            "title": "TrafficProperties",
            "type": "object",
            "properties": {
              "level": { "enum": ["moderate", "heavy", "standstill", "closed"] },
              "source": { "enum": ["staff", "gps"] },
              "road_name": { "$ref": "geoapi-common.v1.schema.json#/$defs/nullableString" },
              "confidence": {
                "description": "GPS stretches only: high when at least 5 different taxis drove every part lately, medium when the weakest part had 3 or 4. Lately is the last 3 minutes when enough taxis drove then, otherwise the last 10. null for staff stretches.",
                "enum": ["high", "medium", null]
              },
              "updated_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$" },
              "expires_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$" }
            },
            "required": ["level", "source", "road_name", "updated_at", "expires_at"],
            "additionalProperties": false
          }
        },
        "required": ["type", "id", "geometry", "properties"],
        "additionalProperties": false
      }
    },
    "generated_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$" },
    "attribution": { "$ref": "geoapi-common.v1.schema.json#/$defs/attribution" }
  },
  "required": ["type", "features", "generated_at", "attribution"],
  "additionalProperties": false
}
