{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://mapeo.world/schemas/observation/v5.json",
  "title": "Observation",
  "description": "An observation is something that has been observed at a particular time and place. It is a subjective statement of 'I saw/heard this, here'",
  "definitions": {
    "position": {
      "description": "Position details",
      "type": "object",
      "properties": {
        "timestamp": {
          "description": "Timestamp of when the current position was obtained",
          "type": "number"
        },
        "mocked": {
          "description": "`true` if the position was mocked",
          "type": "boolean",
          "default": false
        },
        "coords": {
          "description": "Position details, should be self explanatory. Units in meters",
          "type": "object",
          "properties": {
            "altitude": {
              "type": "number"
            },
            "heading": {
              "type": "number"
            },
            "longitude": {
              "type": "number"
            },
            "speed": {
              "type": "number"
            },
            "latitude": {
              "type": "number"
            },
            "accuracy": {
              "type": "number"
            }
          }
        }

      }
    }
  },
  "type": "object",
  "allOf":[{"$ref": "../common/v1.json"}],
  "properties": {
    "schemaType": {
      "description": "Must be `Observation`",
      "type": "string",
      "enum": ["Observation"]
    },
    "schemaVersion": {
      "description": "Version of this schema. Should increment for breaking changes to the schema",
      "type": "number",
      "minimum": 1,
      "enum": [5]
    },
    "lat": {
      "description": "latitude of the observation",
      "type": ["number", "null"],
      "minimum": -90,
      "maximum": 90
    },
    "lon": {
      "description": "longitude of the observation",
      "type": ["number", "null"],
      "minimum": -180,
      "maximum": 180
    },
    "metadata": {
      "description": "Additional metadata associated with the observation (e.g. location precision, altitude, heading)",
      "type": "object",
      "properties": {
        "position": {
          "$ref": "#/definitions/position",
          "description": "Details of the position recorded for the observation"
        },
        "lastSavedPosition": {
          "$ref": "#/definitions/position",
          "description": "Details of the last saved position when the observation was recorded - useful if position is not recorded"
        },
        "positionProvider": {
          "description": "Details of the location providers that were available on the device when the observation was recorded",
          "type": "object",
          "properties": {
            "gpsAvailable": {
              "description": "Whether the user has enabled GPS for device location (this is not the same as whether location is turned on or off, this is a device setting whether to use just wifi and bluetooth or use GPS for location)",
              "type": "boolean"
            },
            "passiveAvailable": {
              "description": "Whether the device is configured to lookup location based on wifi and bluetooth networks",
              "type": "boolean"
            },
            "locationServicesEnabled": {
              "description": "Has the user enabled location services on the device (this is often turned off when the device is in airplane mode)",
              "type": "boolean"
            },
            "networkAvailable": {
              "description": "Whether the device can lookup location based on cell phone towers",
              "type": "boolean"
            }
          }
        },
        "manualLocation": {
          "description": "Whether location has been set manually",
          "type": "boolean",
          "default": false
        }
      },
      "additionalProperties": true
    },
    "refs": {
      "type": "array",
      "description": "References to any nodes or ways that this observation is related to.",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "description": "ID of the element that this observation references",
            "type": "string"
          }
        },
        "required": ["id"]
      }
    },
    "attachments": {
      "type": "array",
      "description": "media or other data that are attached to this observation",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "unique ID that identifies the attachment"
          },
          "type": {
            "type": "string",
            "description": "string that describes the type of the attachment"
          }
        },
        "required": ["id"]
      }
    },
    "tags": {
      "type": "object",
      "description": "User-defined key-value pairs relevant to this observation",
      "properties": {},
      "additionalProperties": true
    }
  },
  "required": ["id", "version", "created_at", "schemaType", "schemaVersion"]
}
