{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hupe1980.github.io/imsys/contracts/events/v1/de.imsys.gateway.read.completed.json",
  "title": "de.imsys.gateway.read.completed",
  "description": "A gateway read reached its meter and its readings are committed. Personal data: confidential, GDPR, standard.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "job",
    "gateway",
    "window",
    "readings"
  ],
  "properties": {
    "client_reference": {
      "description": "The submitter's reference for the read, byte for byte; mirrored in the event's subject (REF-2). A successor inherits its predecessor's.",
      "type": "string",
      "pattern": "^[\\x21-\\x7e]{1,128}$"
    },
    "job": {
      "description": "The desk's read ID.",
      "type": "integer",
      "minimum": 1
    },
    "gateway": {
      "description": "The gateway's wake-up recipient, 18 lowercase hex digits.",
      "type": "string",
      "pattern": "^[0-9a-f]{18}$"
    },
    "metering_point": {
      "description": "The metering point bound to the gateway when the read was submitted (Messlokation or Marktlokation ID). Absent when none was bound.",
      "type": "string",
      "pattern": "\\S",
      "maxLength": 160
    },
    "window": {
      "description": "The three quarter-hour slots requested.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "end",
        "period_seconds"
      ],
      "properties": {
        "start": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
          "description": "First slot, inclusive."
        },
        "end": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
          "description": "End of the last slot, exclusive."
        },
        "period_seconds": {
          "const": 900
        }
      }
    },
    "readings": {
      "description": "One reading per filled slot, in slot order.",
      "type": "array",
      "maxItems": 3,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reference",
          "measured",
          "value",
          "unit"
        ],
        "properties": {
          "reference": {
            "type": "string",
            "format": "date-time",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
            "description": "The slot's scheduled registration instant."
          },
          "measured": {
            "type": "string",
            "format": "date-time",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
            "description": "When the meter captured the value."
          },
          "value": {
            "description": "The register value as an exact decimal, never rounded. 167 characters hold any 128-bit coefficient at any scale from -128 to 127.",
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$",
            "maxLength": 167
          },
          "unit": {
            "description": "The register's unit.",
            "const": "Wh"
          },
          "status": {
            "description": "The meter's status word, when it sent one.",
            "type": "integer",
            "minimum": 0,
            "maximum": 4294967295
          }
        }
      }
    }
  }
}
