{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://airaware.labs.phan.global/schema/airaware-observation.schema.json",
  "title": "AirAware Observation",
  "type": "object",
  "required": ["schema_version", "id", "record_type", "domain", "signals", "location", "time", "source"],
  "additionalProperties": true,
  "properties": {
    "schema_version": {
      "const": "airaware.observation.v1"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "record_type": {
      "type": "string",
      "enum": ["observation", "forecast", "alert", "event", "layer"]
    },
    "domain": {
      "type": "string",
      "enum": ["wastewater", "outdoor_air", "indoor_air", "pollen", "wildfire_smoke", "weather", "weather_alert", "disaster", "other"]
    },
    "signals": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["signal"],
        "additionalProperties": true,
        "properties": {
          "signal": { "type": "string" },
          "label": { "type": "string" },
          "value": { "type": ["number", "string", "boolean", "null"] },
          "unit": { "type": ["string", "null"] },
          "level": {
            "type": ["string", "null"],
            "enum": ["very_low", "low", "moderate", "high", "very_high", "extreme", "good", "fair", "poor", "unknown", null]
          },
          "category": { "type": ["string", "null"] },
          "method": { "type": ["string", "null"] },
          "basis": { "type": ["string", "null"] },
          "index": {
            "type": ["object", "null"],
            "additionalProperties": true,
            "properties": {
              "system": { "type": "string" },
              "value": { "type": ["number", "string", "null"] },
              "category": { "type": ["string", "null"] }
            }
          }
        }
      }
    },
    "location": {
      "type": "object",
      "required": ["label"],
      "additionalProperties": true,
      "properties": {
        "label": { "type": "string" },
        "sublabel": { "type": ["string", "null"] },
        "country": { "type": ["string", "null"] },
        "admin1": { "type": ["string", "null"] },
        "admin2": { "type": ["string", "null"] },
        "site_id": { "type": ["string", "number", "null"] },
        "site_name": { "type": ["string", "null"] },
        "lat": { "type": ["number", "null"], "minimum": -90, "maximum": 90 },
        "lon": { "type": ["number", "null"], "minimum": -180, "maximum": 180 },
        "geometry_ref": { "type": ["string", "null"] },
        "location_type": {
          "type": ["string", "null"],
          "enum": [
            "admin_area",
            "monitoring_site",
            "sewershed",
            "watershed",
            "school",
            "business",
            "public_venue",
            "healthcare",
            "residential",
            "mobile_sensor",
            "alert_area",
            "fire_perimeter",
            "smoke_plume",
            "map_tile",
            "unknown",
            null
          ]
        },
        "address": {
          "type": ["object", "null"],
          "additionalProperties": true,
          "properties": {
            "street": { "type": ["string", "null"] },
            "street2": { "type": ["string", "null"] },
            "city": { "type": ["string", "null"] },
            "admin1": { "type": ["string", "null"] },
            "admin2": { "type": ["string", "null"] },
            "postal_code": { "type": ["string", "null"] },
            "country": { "type": ["string", "null"] },
            "formatted": { "type": ["string", "null"] }
          }
        },
        "contact": {
          "type": ["object", "null"],
          "additionalProperties": true,
          "properties": {
            "name": { "type": ["string", "null"] },
            "organization": { "type": ["string", "null"] },
            "website": { "type": ["string", "null"] },
            "phone": { "type": ["string", "null"] },
            "email": { "type": ["string", "null"] },
            "source_url": { "type": ["string", "null"] }
          }
        },
        "privacy": { "type": ["string", "null"] },
        "confidence": { "type": ["string", "null"] }
      }
    },
    "time": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "observed_at": { "type": ["string", "null"], "format": "date-time" },
        "period_start": { "type": ["string", "null"] },
        "period_end": { "type": ["string", "null"] },
        "valid_from": { "type": ["string", "null"] },
        "valid_to": { "type": ["string", "null"] },
        "fetched_at": { "type": ["string", "null"], "format": "date-time" }
      }
    },
    "source": {
      "type": "object",
      "required": ["id", "name"],
      "additionalProperties": true,
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "url": { "type": ["string", "null"] },
        "license_or_terms": { "type": ["string", "null"] },
        "access": { "type": ["string", "null"] },
        "adapter_version": { "type": ["string", "null"] }
      }
    },
    "quality": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "confidence": { "type": ["string", "null"] },
        "freshness": { "type": ["string", "null"] },
        "observation_kind": {
          "type": ["string", "null"],
          "enum": ["observed", "modelled", "interpolated", "forecast", "community_sensor", "admin_area", "unknown", null]
        },
        "warnings": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "display": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "title": { "type": ["string", "null"] },
        "level": { "type": ["string", "null"] },
        "summary": { "type": ["string", "null"] },
        "color": { "type": ["string", "null"] }
      }
    },
    "raw": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "raw_ref": { "type": ["string", "null"] },
        "provider_record_id": { "type": ["string", "number", "null"] }
      }
    }
  }
}
