{
  "openapi": "3.1.0",
  "info": {
    "title": "imsys gateway administration desk",
    "version": "1",
    "summary": "Submit, dispatch and inspect smart meter gateway reads.",
    "description": "The REST API of `gwad`, the operator desk of a smart meter gateway administrator. A consumer submits a read of a commissioned gateway with its own `client_reference`, an employee with the dispatcher role dispatches it, and the outcome arrives as a signed CloudEvent carrying the same reference (`de.imsys.gateway.read.completed`, `…failed`, `…superseded`; see https://hupe1980.github.io/imsys/guide/events/).\n\n**Idempotency.** `submitRead` takes `client_reference` in the body and the same value in `Idempotency-Key` (conventions REF-1 to REF-5). A repeat with the same content returns the original read with `201`. The same reference with other content is refused with `422`, a missing or differing header with `400`, a repeat that cannot wait for the first with `409`. References belong to the authenticated employee and are remembered as long as the read exists; reads are never deleted, so the window exceeds 30 days.\n\n**Errors** are RFC 9457 problem details. **Values** are exact: `coefficient × 10^scale`, the coefficient as a decimal string.\n\n**Agents.** Read operations declare `x-mcp` with level `read`. Submitting, dispatching and superseding declare none and are not exposed to an agent (AUT-1, AUT-3). The desk runs no model.",
    "license": {
      "name": "MIT OR Apache-2.0",
      "identifier": "MIT OR Apache-2.0"
    }
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "The desk, on loopback behind the operator's TLS proxy"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "session": []
    }
  ],
  "tags": [
    {
      "name": "reads",
      "description": "Profile reads of commissioned gateways and their dispatch receipts"
    },
    {
      "name": "gateways",
      "description": "The commissioned gateway directory"
    },
    {
      "name": "desk",
      "description": "The signed-in employee and this document"
    }
  ],
  "paths": {
    "/reads": {
      "get": {
        "operationId": "listReads",
        "tags": [
          "reads"
        ],
        "summary": "List reads in the employee's assignments, newest first",
        "x-mcp": {
          "tool": "list_reads",
          "level": "read"
        },
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "succeeded",
                "meter_unavailable",
                "superseded"
              ]
            }
          },
          {
            "name": "dispatch_state",
            "in": "query",
            "description": "The latest receipt's state.",
            "schema": {
              "type": "string",
              "enum": [
                "queued",
                "running",
                "retry_wait",
                "completed",
                "stopped",
                "closed"
              ]
            }
          },
          {
            "name": "recipient",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{18}$"
            }
          },
          {
            "name": "pin",
            "in": "query",
            "description": "With `recipient`: only reads bound to this certificate fingerprint.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{64}$"
            }
          },
          {
            "name": "before",
            "in": "query",
            "description": "Cursor from `next`.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "after",
            "in": "query",
            "description": "Cursor from `previous`. Not together with `before`.",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of reads",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      },
      "post": {
        "operationId": "submitRead",
        "tags": [
          "reads"
        ],
        "summary": "Submit a read of a commissioned gateway",
        "description": "Binds the gateway's current active revision. The read covers three quarter-hours from `window_start`. It stays pending until a dispatcher dispatches it.",
        "x-idempotency": {
          "header": "Idempotency-Key",
          "body": "client_reference",
          "scope": "authenticated employee",
          "retention": "as long as the read exists; reads are never deleted"
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewRead"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The read, for the first request and every identical repeat",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Read"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "The read's URL.",
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "A missing or malformed body, `client_reference` or `Idempotency-Key`, or a header that differs from the body",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "The gateway's revision changed or it was retired, or an identical request is still being processed (with `Retry-After`)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "description": "This `client_reference` already names a read of another gateway, revision or window",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/reads/{id}": {
      "get": {
        "operationId": "getRead",
        "tags": [
          "reads"
        ],
        "summary": "Show a read with its result, receipts and attempts",
        "x-mcp": {
          "tool": "get_read",
          "level": "read"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The read's ID.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          },
          {
            "name": "receipts_before",
            "in": "query",
            "description": "Cursor from `receipts_next`.",
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The read",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadDetail"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/reads/{id}/dispatches": {
      "post": {
        "operationId": "dispatchRead",
        "tags": [
          "reads"
        ],
        "summary": "Dispatch a pending read after reviewing its latest receipt",
        "description": "`after` is the number of the latest receipt the employee reviewed, `0` for none. A lost response is repeated with the same body; it returns the same receipt.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The read's ID.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DispatchDecision"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The receipt has already finished",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "202": {
            "description": "Accepted; follow `Location` to watch the receipt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "The receipt's URL.",
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "Review the read again: a newer receipt, a changed target or no callback listener (`Location` names the read)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/reads/{id}/dispatches/{number}": {
      "get": {
        "operationId": "getDispatch",
        "tags": [
          "reads"
        ],
        "summary": "Show one dispatch receipt",
        "x-mcp": {
          "tool": "get_dispatch",
          "level": "read"
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The read's ID.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          },
          {
            "name": "number",
            "in": "path",
            "required": true,
            "description": "The dispatch receipt's number, from 1.",
            "schema": {
              "type": "integer",
              "format": "int32",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The receipt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/reads/{id}/supersede": {
      "post": {
        "operationId": "supersedeRead",
        "tags": [
          "reads"
        ],
        "summary": "Replace a pending read on an older revision with a reviewed successor",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The read's ID.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Renewal"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The superseded read, naming its successor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Read"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "The read is not pending or the revision is not the current one",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/gateways": {
      "get": {
        "operationId": "listGateways",
        "tags": [
          "gateways"
        ],
        "summary": "Search the gateways in the employee's assignments",
        "x-mcp": {
          "tool": "list_gateways",
          "level": "read"
        },
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "description": "A gateway name or recipient.",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "retired"
              ]
            }
          },
          {
            "name": "after",
            "in": "query",
            "description": "Cursor from `next`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of gateways",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GatewayPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/gateways/{recipient}": {
      "get": {
        "operationId": "getGateway",
        "tags": [
          "gateways"
        ],
        "summary": "Show a gateway's current revision, history and installation",
        "x-mcp": {
          "tool": "get_gateway",
          "level": "read"
        },
        "parameters": [
          {
            "name": "recipient",
            "in": "path",
            "required": true,
            "description": "The gateway recipient: 18 hexadecimal digits.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{18}$"
            }
          },
          {
            "name": "before",
            "in": "query",
            "description": "History cursor from `history.next`.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The gateway",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Gateway"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/session": {
      "get": {
        "operationId": "getSession",
        "tags": [
          "desk"
        ],
        "summary": "Show the signed-in employee and role",
        "responses": {
          "200": {
            "description": "The employee",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/Busy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApi",
        "tags": [
          "desk"
        ],
        "summary": "This document",
        "security": [],
        "responses": {
          "200": {
            "description": "The OpenAPI document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "The 64-hex credential `gwad grant` prints, on a desk without a workforce provider."
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-gwad-session",
        "description": "A workforce desk session after OpenID Connect sign-in. Writes also send `X-CSRF-Token` with the `csrf` value of `getSession`."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "The body's `client_reference`, as an RFC 8941 string (`\"order-7\"`) as in the IETF draft, or the bare value.",
        "schema": {
          "type": "string",
          "maxLength": 300
        },
        "example": "\"order-2026-11-30-0173\""
      }
    },
    "responses": {
      "BadRequest": {
        "description": "A malformed parameter or body",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "No current credential or session",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Forbidden": {
        "description": "A viewer tried to write, or a workforce write lacks its CSRF token",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "NotFound": {
        "description": "No such read or gateway in the employee's assignments",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Busy": {
        "description": "Too many concurrent requests or a full dispatch queue; repeat after `Retry-After`",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Unavailable": {
        "description": "The database is unavailable or the read is busy; repeat after `Retry-After`",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "Timeout": {
        "description": "The request took longer than 32 seconds; inspect the state before repeating",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      },
      "TooLarge": {
        "description": "A body larger than 4 KiB",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/Problem"
            }
          }
        }
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "additionalProperties": false,
        "properties": {
          "type": {
            "type": "string",
            "const": "about:blank"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer",
            "minimum": 400,
            "maximum": 599
          },
          "detail": {
            "type": "string",
            "description": "A sentence for the person at the desk."
          }
        }
      },
      "ClientReference": {
        "type": "string",
        "minLength": 1,
        "maxLength": 128,
        "pattern": "^[!-~]([ -~]*[!-~])?$",
        "description": "Opaque, chosen by the sender, compared byte for byte (conventions REF-1)."
      },
      "NewRead": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "client_reference",
          "recipient",
          "revision",
          "window_start"
        ],
        "properties": {
          "client_reference": {
            "$ref": "#/components/schemas/ClientReference"
          },
          "recipient": {
            "type": "string",
            "pattern": "^[0-9a-fA-F]{18}$",
            "description": "The gateway recipient."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "The gateway revision the submitter reviewed; it must still be the current, active one."
          },
          "window_start": {
            "type": "integer",
            "format": "int64",
            "multipleOf": 900,
            "maximum": 253402298100,
            "description": "Start of the first quarter-hour, in Unix seconds."
          }
        }
      },
      "DispatchDecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "after"
        ],
        "properties": {
          "after": {
            "type": "integer",
            "format": "int32",
            "minimum": 0,
            "maximum": 2147483646,
            "description": "The latest receipt number reviewed, 0 for none."
          }
        }
      },
      "Renewal": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reason",
          "revision"
        ],
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          }
        }
      },
      "Record": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reference_utc",
          "measured_utc",
          "coefficient",
          "scale",
          "meter_status"
        ],
        "properties": {
          "reference_utc": {
            "type": "integer",
            "format": "int64",
            "description": "The quarter-hour, Unix seconds."
          },
          "measured_utc": {
            "type": "integer",
            "format": "int64"
          },
          "coefficient": {
            "type": "string",
            "pattern": "^-?[0-9]+$",
            "description": "Exact integer; the value is coefficient × 10^scale in Wh."
          },
          "scale": {
            "type": "integer",
            "minimum": -128,
            "maximum": 127
          },
          "meter_status": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 4294967295
          }
        }
      },
      "Read": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "id",
          "state",
          "recipient",
          "pin",
          "window_start",
          "revision",
          "created_by",
          "created_by_id",
          "erased"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[1-9][0-9]*$"
          },
          "state": {
            "type": "string",
            "enum": [
              "pending",
              "succeeded",
              "meter_unavailable",
              "superseded"
            ]
          },
          "recipient": {
            "type": "string",
            "pattern": "^[0-9a-f]{18}$",
            "description": "The gateway recipient."
          },
          "pin": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "SHA-256 of the gateway certificate the read is bound to."
          },
          "window_start": {
            "type": "integer",
            "format": "int64"
          },
          "revision": {
            "type": "integer",
            "format": "int64"
          },
          "client_reference": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ClientReference"
              },
              {
                "type": "null"
              }
            ],
            "description": "The submitter's reference; a successor keeps its predecessor's. The outcome event carries it."
          },
          "metering_point": {
            "type": [
              "string",
              "null"
            ],
            "description": "The metering point bound when the read was submitted."
          },
          "erased": {
            "type": "boolean",
            "description": "The household was erased; readings and metering point are gone."
          },
          "created_by": {
            "type": "string"
          },
          "created_by_id": {
            "type": "string"
          },
          "replaced_by": {
            "type": [
              "string",
              "null"
            ]
          },
          "replaced_by_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "predecessor": {
            "type": [
              "string",
              "null"
            ]
          },
          "records": {
            "type": "array",
            "maxItems": 3,
            "items": {
              "$ref": "#/components/schemas/Record"
            },
            "description": "With state `succeeded`."
          },
          "successor": {
            "type": "string",
            "description": "With state `superseded`."
          },
          "replacement_pin": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "With state `superseded`."
          },
          "reason": {
            "type": "string",
            "description": "With state `superseded`."
          }
        }
      },
      "ReadDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Read"
          },
          {
            "type": "object",
            "required": [
              "can_dispatch",
              "callback_available",
              "receipts",
              "gateway_name",
              "current_revision",
              "active",
              "attempts"
            ],
            "properties": {
              "can_dispatch": {
                "type": "boolean"
              },
              "callback_available": {
                "type": "boolean"
              },
              "receipt": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/Receipt"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "The latest receipt."
              },
              "receipts": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "$ref": "#/components/schemas/Receipt"
                }
              },
              "receipts_next": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "gateway_name": {
                "type": "string"
              },
              "current_revision": {
                "type": "integer",
                "format": "int64"
              },
              "active": {
                "type": "boolean"
              },
              "attempts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "employee",
                    "employee_id",
                    "utc",
                    "receipt"
                  ],
                  "properties": {
                    "employee": {
                      "type": "string"
                    },
                    "employee_id": {
                      "type": "string"
                    },
                    "utc": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "receipt": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "ReadSummary": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "state",
          "recipient",
          "window_start",
          "revision",
          "changed",
          "name",
          "receipt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "recipient": {
            "type": "string",
            "pattern": "^[0-9a-f]{18}$",
            "description": "The gateway recipient."
          },
          "window_start": {
            "type": "integer",
            "format": "int64"
          },
          "revision": {
            "type": "integer",
            "format": "int64"
          },
          "changed": {
            "type": "boolean",
            "description": "The gateway's current revision differs from the read's."
          },
          "name": {
            "type": "string"
          },
          "receipt": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "number",
                  "state"
                ],
                "properties": {
                  "number": {
                    "type": "integer"
                  },
                  "state": {
                    "type": "string"
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "ReadPage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reads",
          "next",
          "previous"
        ],
        "properties": {
          "reads": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReadSummary"
            }
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          },
          "previous": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Receipt": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "read",
          "number",
          "employee",
          "employee_id",
          "state",
          "attempts",
          "max_attempts",
          "accepted_at",
          "expires_at",
          "next_eligible_at",
          "reason",
          "monitor",
          "read_url"
        ],
        "properties": {
          "read": {
            "type": "string"
          },
          "number": {
            "type": "integer",
            "minimum": 1
          },
          "employee": {
            "type": "string"
          },
          "employee_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "retry_wait",
              "completed",
              "stopped",
              "closed"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 0
          },
          "max_attempts": {
            "type": "integer"
          },
          "accepted_at": {
            "type": "integer",
            "format": "int64"
          },
          "expires_at": {
            "type": "integer",
            "format": "int64"
          },
          "next_eligible_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why a receipt stopped: `target_changed`, `authority_changed`, `expired`, …"
          },
          "monitor": {
            "type": "string",
            "format": "uri-reference"
          },
          "read_url": {
            "type": "string",
            "format": "uri-reference"
          }
        }
      },
      "GatewaySummary": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "recipient",
          "name",
          "revision",
          "active"
        ],
        "properties": {
          "recipient": {
            "type": "string",
            "pattern": "^[0-9a-f]{18}$",
            "description": "The gateway recipient."
          },
          "name": {
            "type": "string"
          },
          "revision": {
            "type": "integer",
            "format": "int64"
          },
          "active": {
            "type": "boolean"
          }
        }
      },
      "GatewayPage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "gateways",
          "next"
        ],
        "properties": {
          "gateways": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/GatewaySummary"
            }
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Gateway": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "recipient",
          "revision",
          "active",
          "pin",
          "history",
          "installation"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "recipient": {
            "type": "string",
            "pattern": "^[0-9a-f]{18}$",
            "description": "The gateway recipient."
          },
          "revision": {
            "type": "integer",
            "format": "int64"
          },
          "active": {
            "type": "boolean"
          },
          "pin": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$",
            "description": "SHA-256 of the current certificate."
          },
          "history": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "revisions",
              "next"
            ],
            "properties": {
              "revisions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "revision",
                    "active",
                    "name",
                    "pin",
                    "actor",
                    "reason",
                    "receipt",
                    "at"
                  ],
                  "properties": {
                    "revision": {
                      "type": "integer"
                    },
                    "active": {
                      "type": "boolean"
                    },
                    "name": {
                      "type": "string"
                    },
                    "pin": {
                      "type": "string"
                    },
                    "actor": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    },
                    "receipt": {
                      "type": "string",
                      "description": "The commissioning request ID."
                    },
                    "at": {
                      "type": "string"
                    }
                  }
                }
              },
              "next": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "installation": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "metering_point",
                  "units"
                ],
                "properties": {
                  "metering_point": {
                    "type": "string"
                  },
                  "units": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "Session": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "employee",
          "employee_id",
          "writable",
          "has_scope",
          "csrf"
        ],
        "properties": {
          "employee": {
            "type": "string"
          },
          "employee_id": {
            "type": "string"
          },
          "writable": {
            "type": "boolean",
            "description": "Dispatcher role."
          },
          "has_scope": {
            "type": "boolean"
          },
          "csrf": {
            "type": [
              "string",
              "null"
            ],
            "description": "Send as `X-CSRF-Token` on writes in a workforce session."
          }
        }
      }
    }
  }
}
