{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://teachthecompany.com/node-lab/source/telemetry.schema.json",
  "title": "Node Lab live-generated workshop snapshot",
  "description": "Three fictional workshop stations generated by the Node-RED backend. No physical sensor or customer data is represented.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "sampleId",
    "sampleKey",
    "generatedAt",
    "intervalMs",
    "configured_demo_temperature_limit_c",
    "validated_temperature_c",
    "comfort_margin_c",
    "stations",
    "scenario",
    "source",
    "events",
    "runtime"
  ],
  "properties": {
    "schemaVersion": {"const": "2.0.0"},
    "sampleId": {"type": "integer", "minimum": 1},
    "sampleKey": {"type": "string", "pattern": "^NL-[0-9]{8}$"},
    "generatedAt": {"type": "string", "format": "date-time"},
    "intervalMs": {"const": 1500},
    "generationLatencyMs": {"type": "number", "minimum": 0},
    "configured_demo_temperature_limit_c": {"type": "number"},
    "validated_temperature_c": {"type": ["number", "null"]},
    "comfort_margin_c": {
      "type": ["number", "null"],
      "description": "Configured demo temperature limit minus validated temperature, in degrees Celsius."
    },
    "scenario": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "scope"],
      "properties": {
        "id": {"enum": ["normal", "heating", "fault", "recover"]},
        "label": {"type": "string"},
        "scope": {"const": "this-response-only"}
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "hardwareConnected", "physicalSensors", "customerData"],
      "properties": {
        "kind": {"const": "live-generated-emulation"},
        "hardwareConnected": {"const": false},
        "physicalSensors": {"const": false},
        "customerData": {"const": false}
      }
    },
    "stations": {
      "type": "array",
      "minItems": 3,
      "maxItems": 3,
      "items": {"$ref": "#/$defs/station"}
    },
    "events": {
      "type": "array",
      "maxItems": 4,
      "items": {"$ref": "#/$defs/event"}
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "nodeRedVersion",
        "flowVersion",
        "uptimeSeconds",
        "ticksGenerated",
        "apiResponses",
        "messagesProcessed",
        "generationLatencyMs",
        "responseBuildMs",
        "tickAgeMs",
        "generatorIntervalMs"
      ],
      "properties": {
        "nodeRedVersion": {"const": "5.0.8"},
        "flowVersion": {"const": "2.0.0"},
        "uptimeSeconds": {"type": "integer", "minimum": 0},
        "ticksGenerated": {"type": "integer", "minimum": 1},
        "apiResponses": {"type": "integer", "minimum": 1},
        "messagesProcessed": {"type": "integer", "minimum": 1},
        "generationLatencyMs": {"type": "number", "minimum": 0},
        "responseBuildMs": {"type": "number", "minimum": 0},
        "tickAgeMs": {"type": "number", "minimum": 0},
        "generatorIntervalMs": {"const": 1500}
      }
    }
  },
  "$defs": {
    "station": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "zone",
        "state",
        "health",
        "quality",
        "observedAt",
        "ageMs",
        "temperatureC",
        "thresholdC",
        "comfort_margin_c",
        "powerKw",
        "processValue",
        "processLabel",
        "processUnit"
      ],
      "properties": {
        "id": {"enum": ["cnc-cell", "curing-oven", "packing-line"]},
        "name": {"type": "string"},
        "zone": {"type": "string"},
        "state": {"type": "string"},
        "health": {"enum": ["NORMAL", "WATCH", "ALERT", "STALE", "RECOVERING"]},
        "quality": {"enum": ["good", "missing"]},
        "observedAt": {"type": "string", "format": "date-time"},
        "ageMs": {"type": "number", "minimum": 0},
        "temperatureC": {"type": ["number", "null"]},
        "thresholdC": {"type": "number"},
        "comfort_margin_c": {
          "type": ["number", "null"],
          "description": "Station limit minus validated station temperature, in degrees Celsius."
        },
        "powerKw": {"type": ["number", "null"], "minimum": 0},
        "processValue": {"type": "number"},
        "processLabel": {"type": "string"},
        "processUnit": {"type": "string"}
      }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": ["level", "stationId", "message", "id", "at"],
      "properties": {
        "level": {"enum": ["info", "watch", "alert", "recovery"]},
        "stationId": {"type": ["string", "null"]},
        "message": {"type": "string"},
        "id": {"type": "string"},
        "at": {"type": "string", "format": "date-time"}
      }
    }
  }
}
