{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://phicomm-io.github.io/iotcloud-community-protocols/contracts/schemas/sensor-values-v3.schema.json",
  "title": "Schema 3 descriptor-bound numeric snapshot with PM sample age extension",
  "type": "object",
  "required": [
    "schema",
    "device_id",
    "boot",
    "sequence",
    "descriptor_revision",
    "sensors"
  ],
  "properties": {
    "schema": {
      "const": 3,
      "type": "integer"
    },
    "device_id": {
      "type": "string",
      "pattern": "^[0-9a-f]{12}$"
    },
    "boot": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4294967295
    },
    "sequence": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4294967295
    },
    "descriptor_revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4294967295
    },
    "sensors": {
      "type": "object",
      "maxProperties": 16,
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_]{0,31}$"
      },
      "additionalProperties": {
        "type": "object",
        "required": [
          "value",
          "valid",
          "age_ms"
        ],
        "properties": {
          "value": {},
          "valid": {
            "type": "boolean"
          },
          "age_ms": {
            "type": "integer",
            "minimum": 0,
            "maximum": 4294967295
          }
        },
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "valid": {
                  "const": false
                }
              }
            },
            "then": {
              "properties": {
                "value": {
                  "type": "null"
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "valid": {
                  "const": true
                }
              }
            },
            "then": {
              "properties": {
                "value": {
                  "type": "number",
                  "x-float32Finite": true
                },
                "age_ms": {
                  "maximum": 19999
                }
              }
            }
          }
        ]
      },
      "properties": {
        "pm25": {
          "type": "object",
          "required": [
            "value",
            "valid",
            "age_ms"
          ],
          "properties": {
            "value": {},
            "valid": {
              "type": "boolean"
            },
            "age_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 4294967295
            },
            "max_age_ms": {
              "type": "integer",
              "minimum": 1,
              "maximum": 3600000
            }
          },
          "additionalProperties": false,
          "allOf": [
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": false
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "null"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": true
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "number",
                    "x-float32Finite": true
                  },
                  "age_ms": {
                    "maximum": 3599999
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": true
                  }
                },
                "not": {
                  "required": [
                    "max_age_ms"
                  ]
                }
              },
              "then": {
                "properties": {
                  "age_ms": {
                    "maximum": 19999
                  }
                }
              }
            }
          ]
        },
        "pm10": {
          "type": "object",
          "required": [
            "value",
            "valid",
            "age_ms"
          ],
          "properties": {
            "value": {},
            "valid": {
              "type": "boolean"
            },
            "age_ms": {
              "type": "integer",
              "minimum": 0,
              "maximum": 4294967295
            },
            "max_age_ms": {
              "type": "integer",
              "minimum": 1,
              "maximum": 3600000
            }
          },
          "additionalProperties": false,
          "allOf": [
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": false
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "null"
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": true
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "number",
                    "x-float32Finite": true
                  },
                  "age_ms": {
                    "maximum": 3599999
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "valid": {
                    "const": true
                  }
                },
                "not": {
                  "required": [
                    "max_age_ms"
                  ]
                }
              },
              "then": {
                "properties": {
                  "age_ms": {
                    "maximum": 19999
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "additionalProperties": false,
  "x-runtimePolicy": "A valid field requires age_ms < max_age_ms (default 20000), plus independent communication lease. Metadata unit/type binding is mandatory; age extension never changes replay handling."
}
