{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Door state",
  "description": "All encompassing states of a door or airlock.",
  "subtopic": "/state",
  "type": "object",
  "required": [
    "timestamp",
    "version",
    "serialNumber",
    "connectionState",
    "doorState"
  ],
  "properties": {
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp in ISO8601 Format (YYYY-MM-DDTHH:mm:ss.sssZ). The timestamp defines the point in time at which the message was sent.",
      "examples": [
        "2015-10-21T16:29:00.000Z"
      ]
    },
    "version": {
      "type": "string",
      "description": "Version of the M2X protocol [Major].[Minor].[Patch] (e.g. 1.3.2)",
      "examples": [
        "1.0.0"
      ]
    },
    "serialNumber": {
      "type": "string",
      "description": "Serial number of the door."
    },
    "manufacturer": {
      "type": "string",
      "description": "Manufacturer of the door."
    },
    "connectionState": {
      "type": "string",
      "enum": [
        "ONLINE",
        "OFFLINE",
        "CONNECTION_BROKEN"
      ],
      "description": "ONLINE: connection between door and broker is active. OFFLINE: connection between door and broker has gone offline in a coordinated way. CONNECTION_BROKEN: The connection between door and broker has unexpectedly ended."
    },
    "doorState": {
      "type": "object",
      "description": "The door state contains the current status of the door, including its requests.",
      "required": [
        "doorId",
        "doorStatus",
        "requestStates"
      ],
      "properties": {
        "doorId": {
          "type": "string",
          "description": "Unique identifier of the individual door."
        },
        "doorStatus": {
          "type": "string",
          "description": "Indicates if the door is open.",
          "enum": [
            "OPEN",
            "CLOSED",
            "OPENING",
            "CLOSING"
          ]
        },
        "requestStates": {
          "type": "array",
          "description": "Array of upcoming and current requests.",
          "items": {
            "type": "object",
            "required": [
              "requestId",
              "requestStatus"
            ],
            "properties": {
              "requestId": {
                "type": "string",
                "description": "Id of a request to be referred to in this state.",
                "examples": [
                  "requestAccess_1337"
                ]
              },
              "requestType": {
                "type": "string",
                "description": "requestType of the request. Optional: Only for informational or visualization purposes."
              },
              "requestStatus": {
                "type": "string",
                "description": "Status of the request.",
                "enum": [
                  "PENDING",
                  "RUNNING",
                  "PAUSED",
                  "FINISHED",
                  "FAILED"
                ]
              },
              "resultDescription": {
                "type": "string",
                "description": "Description of the result. Errors will be transmitted in errors."
              }
            }
          }
        },
        "errors": {
          "type": "array",
          "description": "Array of error-objects. All active errors of the door should be in the list. An empty array indicates that the door has no active errors.",
          "items": {
            "type": "object",
            "required": [
              "errorType",
              "errorLevel"
            ],
            "properties": {
              "errorType": {
                "type": "string",
                "description": "Type of error."
              },
              "requestId": {
                "type": "string",
                "description": "Id of the request that is caused by or related to the error."
              },
              "errorDescription": {
                "type": "string",
                "description": "Verbose description of error."
              },
              "errorLevel": {
                "type": "string",
                "description": "Description of the error level, which is warning or fatal. WARNING: Door is ready to start (e.g., maintenance cycle expiration warning). FATAL: Door is not in running condition, user intervention required.",
                "enum": [
                  "WARNING",
                  "FATAL"
                ]
              }
            }
          }
        }
      }
    }
  }
}
