{
  "openapi": "3.1.0",
  "info": {
    "title": "qes.dev API",
    "version": "1.0.0",
    "summary": "API for qes.dev signing, device orchestration, diagnostics, webhooks, and tenant administration.",
    "description": "The qes.dev API provides a unified integration layer for qualified-signature workflows, device orchestration, diagnostics, webhooks, and tenant administration across local and cloud-connected signing paths.",
    "termsOfService": "https://qes.dev/legal/terms-of-service",
    "contact": {
      "name": "API Support",
      "url": "https://qes.dev/contact",
      "email": "support@qes.dev"
    }
  },
  "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
  "servers": [
    {
      "url": "https://qes-socket.domain.com/api",
      "description": "Example production API base URL"
    },
    {
      "url": "{host}/api",
      "description": "Environment-based server template",
      "variables": {
        "host": {
          "default": "https://qes-socket.domain.com",
          "description": "Base host for the qes.dev API environment"
        }
      }
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Signing",
      "description": "Operations that initiate signing or locally-executed requests.",
      "x-page-title": "Signing",
      "x-page-description": "Submit XML for qualified signing and trigger local execution through the unified qes.dev signing layer."
    },
    {
      "name": "Devices",
      "description": "Device discovery, metadata, and diagnostics.",
      "x-page-title": "Devices",
      "x-page-description": "Inspect connected devices, retrieve metadata, and trigger diagnostics."
    },
    {
      "name": "Webhooks",
      "description": "Webhook subscription and delivery-log management.",
      "x-page-title": "Webhooks",
      "x-page-description": "Subscribe to operational events such as device connectivity and QES state changes."
    },
    {
      "name": "Tenant",
      "description": "Tenant-level configuration and API key management.",
      "x-page-title": "Tenant",
      "x-page-description": "Manage tenant configuration, branding settings, and API keys."
    },
    {
      "name": "Health",
      "description": "Service and dependency health checks.",
      "x-page-title": "Health",
      "x-page-description": "Verify service, messaging, and database readiness."
    },
    {
      "name": "Debug",
      "description": "Debug logs and support-facing retrieval endpoints.",
      "x-page-title": "Debug",
      "x-page-description": "Retrieve diagnostic and device log outputs for support and troubleshooting."
    }
  ],
  "externalDocs": {
    "description": "Developer documentation",
    "url": "https://qes.dev/developer-api"
  },
  "paths": {
    "/qes-sign-xml": {
      "post": {
        "tags": [
          "Signing"
        ],
        "summary": "Submit XML for qualified signing",
        "description": "Creates a signing request that is routed to the appropriate connected execution path. The desktop client performs the local signing operation and the API returns the signed XML or an error.",
        "operationId": "signXml",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/XmlSigningRequest"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/XmlSigningRequestExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed XML returned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XmlSigningResponse"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/XmlSigningResponseExample"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "504": {
            "$ref": "#/components/responses/UpstreamTimeout"
          }
        }
      }
    },
    "/tunnel": {
      "post": {
        "tags": [
          "Signing"
        ],
        "summary": "Execute a tunneled local request via the desktop client",
        "description": "Creates a request that is executed through the connected desktop environment. This is intended for workflows where the request must originate locally or attach local signing context.",
        "operationId": "createTunnelRequest",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TunnelRequest"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/TunnelRequestExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tunneled response returned successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TunnelResponse"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/TunnelResponseExample"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "504": {
            "$ref": "#/components/responses/UpstreamTimeout"
          }
        }
      }
    },
    "/devices": {
      "get": {
        "tags": [
          "Devices"
        ],
        "summary": "List devices online for the current tenant",
        "operationId": "listDevices",
        "responses": {
          "200": {
            "description": "Online devices returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Device"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/devices/{deviceId}": {
      "get": {
        "tags": [
          "Devices"
        ],
        "summary": "Get device details",
        "operationId": "getDevice",
        "parameters": [
          {
            "$ref": "#/components/parameters/DeviceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Device details returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Device"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/DeviceExample"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/devices/{deviceId}/diagnostics": {
      "post": {
        "tags": [
          "Devices"
        ],
        "summary": "Trigger a diagnostics run on a device",
        "operationId": "runDeviceDiagnostics",
        "parameters": [
          {
            "$ref": "#/components/parameters/DeviceId"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiagnosticsRequest"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/DiagnosticsRequestExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Diagnostics result returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiagnosticsResponse"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/DiagnosticsResponseExample"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "504": {
            "$ref": "#/components/responses/UpstreamTimeout"
          }
        }
      }
    },
    "/debug/logs": {
      "get": {
        "tags": [
          "Debug"
        ],
        "summary": "Retrieve uploaded device logs",
        "operationId": "getDebugLogs",
        "parameters": [
          {
            "name": "deviceId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Optional device filter."
          }
        ],
        "responses": {
          "200": {
            "description": "Device logs returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DeviceLog"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "List configured webhooks",
        "operationId": "listWebhooks",
        "responses": {
          "200": {
            "description": "Webhook subscriptions returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookSubscription"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{topic}": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Create or update a webhook for a topic",
        "operationId": "upsertWebhook",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookTopic"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookUpsertRequest"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookUpsertRequestExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook created or updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscription"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/WebhookSubscriptionExample"
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Delete a webhook for a topic",
        "operationId": "deleteWebhook",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookTopic"
          }
        ],
        "responses": {
          "204": {
            "description": "Webhook deleted"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/webhooks/{topic}/logs": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Retrieve delivery attempt logs for a webhook topic",
        "operationId": "getWebhookLogs",
        "parameters": [
          {
            "$ref": "#/components/parameters/WebhookTopic"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook logs returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookLog"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/config": {
      "get": {
        "tags": [
          "Tenant"
        ],
        "summary": "Get tenant configuration",
        "operationId": "getTenantConfig",
        "responses": {
          "200": {
            "description": "Tenant configuration returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantConfig"
                }
              }
            }
          }
        }
      }
    },
    "/admin/config": {
      "patch": {
        "tags": [
          "Tenant"
        ],
        "summary": "Update tenant configuration",
        "operationId": "updateTenantConfig",
        "requestBody": {
          "required": true,
          "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantConfigPatch"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/TenantConfigPatchExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tenant configuration updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantConfig"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/TenantConfigExample"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/admin/api-keys": {
      "get": {
        "tags": [
          "Tenant"
        ],
        "summary": "List API keys",
        "operationId": "listApiKeys",
        "responses": {
          "200": {
            "description": "API keys returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKey"
                      }
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Tenant"
        ],
        "summary": "Create a new API key",
        "operationId": "createApiKey",
        "requestBody": {
          "required": true,
          "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateApiKeyRequest"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/CreateApiKeyRequestExample"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyWithSecret"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/ApiKeyWithSecretExample"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/admin/api-keys/{id}": {
      "delete": {
        "tags": [
          "Tenant"
        ],
        "summary": "Delete an API key",
        "operationId": "deleteApiKey",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "API key deleted"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Service health check",
        "operationId": "getHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Health status returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/HealthStatusExample"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health/ably": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Ably connection health check",
        "operationId": "getAblyHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Ably health status returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/HealthStatusExample"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health/database": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Database health check",
        "operationId": "getDatabaseHealth",
        "security": [],
        "responses": {
          "200": {
            "description": "Database health status returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/HealthStatusExample"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "device.connected": {
      "post": {
        "summary": "Device connected event",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEventEnvelope"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookEventEnvelopeExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "device.disconnected": {
      "post": {
        "summary": "Device disconnected event",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEventEnvelope"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookEventEnvelopeExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "qes.connected": {
      "post": {
        "summary": "QES connected event",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEventEnvelope"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookEventEnvelopeExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "qes.disconnected": {
      "post": {
        "summary": "QES disconnected event",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEventEnvelope"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookEventEnvelopeExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "qes.state.changed": {
      "post": {
        "summary": "QES state changed event",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEventEnvelope"
              },
              "examples": {
                "default": {
                  "$ref": "#/components/examples/WebhookEventEnvelopeExample"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Tenant-scoped API key used for all cloud-to-server API calls."
      }
    },
    "parameters": {
      "DeviceId": {
        "name": "deviceId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "WebhookTopic": {
        "name": "topic",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "device.connected",
            "device.disconnected",
            "qes.connected",
            "qes.disconnected",
            "qes.state.changed"
          ]
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request payload or unsupported input.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Requested resource not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Conflict": {
        "description": "Request could not be completed because the target device or workflow state is incompatible.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "UpstreamTimeout": {
        "description": "No desktop client or downstream execution path responded before timeout.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "examples": {
      "XmlSigningRequestExample": {
        "value": {
          "id": "9a6f6dbe-6ec4-4676-9f79-657af79d9a31",
          "qesId": "84ad4b62-d1eb-4c1b-9f71-09136fd6d450",
          "xml": "<Invoice>...</Invoice>",
          "profile": "XAdES_BASELINE_B",
          "options": {
            "digestAlgorithm": "sha256",
            "canonicalization": "c14n"
          }
        }
      },
      "XmlSigningResponseExample": {
        "value": {
          "id": "9a6f6dbe-6ec4-4676-9f79-657af79d9a31",
          "signedXml": "<InvoiceSigned>...</InvoiceSigned>",
          "deviceId": "1bfcb21d-e184-4a50-a34d-cc71798396f2",
          "completedAt": "2026-04-04T10:00:00Z"
        }
      },
      "TunnelRequestExample": {
        "value": {
          "id": "94de1dca-5575-4e75-b5c6-521a588dad47",
          "qesId": "84ad4b62-d1eb-4c1b-9f71-09136fd6d450",
          "method": "POST",
          "url": "https://nhif.bg/example",
          "headers": {
            "Content-Type": "application/xml"
          },
          "dataBinary": "YmFzZTY0LXBheWxvYWQ="
        }
      },
      "TunnelResponseExample": {
        "value": {
          "id": "94de1dca-5575-4e75-b5c6-521a588dad47",
          "status": 200,
          "headers": {
            "Content-Type": "application/xml"
          },
          "responseBinary": "YmFzZTY0LXJlc3BvbnNl"
        }
      },
      "DeviceExample": {
        "value": {
          "id": "1bfcb21d-e184-4a50-a34d-cc71798396f2",
          "status": "online",
          "platform": "windows",
          "appVersion": "0.1.0",
          "lastSeenAt": "2026-04-04T10:00:00Z",
          "qesCertificates": [
            {
              "id": "84ad4b62-d1eb-4c1b-9f71-09136fd6d450",
              "label": "Dr. Ivanov QES",
              "provider": "InfoNotary",
              "state": "connected",
              "validTo": "2027-04-04T00:00:00Z"
            }
          ]
        }
      },
      "DiagnosticsRequestExample": {
        "value": {
          "id": "f51b1486-febe-4bd5-9bfc-a37ab354f852",
          "scope": [
            "drivers",
            "token"
          ]
        }
      },
      "DiagnosticsResponseExample": {
        "value": {
          "id": "f51b1486-febe-4bd5-9bfc-a37ab354f852",
          "deviceId": "1bfcb21d-e184-4a50-a34d-cc71798396f2",
          "result": {
            "drivers": "ok",
            "token": "ok"
          }
        }
      },
      "WebhookUpsertRequestExample": {
        "value": {
          "url": "https://example.com/hook",
          "hmacSecret": "base64-secret",
          "retryPolicy": {
            "maxRetries": 3
          },
          "active": true
        }
      },
      "WebhookSubscriptionExample": {
        "value": {
          "id": "64fa1981-849d-4026-bc83-a59e9ba646ec",
          "topic": "qes.state.changed",
          "url": "https://example.com/hook",
          "active": true,
          "retryPolicy": {
            "maxRetries": 3
          },
          "createdAt": "2026-04-04T10:00:00Z"
        }
      },
      "WebhookEventEnvelopeExample": {
        "value": {
          "id": "2d5c4fa0-eb20-42c8-87fa-d7a864ceb2b6",
          "event": "qes.state.changed",
          "occurredAt": "2026-04-04T10:00:00Z",
          "tenantId": "medentic-production",
          "deviceId": "2dfe92c9-dfb8-4f90-9396-3f416e14fbee",
          "qesId": "b94d08a1-cb83-4d1f-a9de-e480b752fdfd",
          "payload": {
            "state": "locked",
            "label": "Dr. Ivanov QES"
          }
        }
      },
      "TenantConfigExample": {
        "value": {
          "branding": {
            "name": "Medentic"
          },
          "termsUrl": "https://qes.dev/legal/terms-of-service",
          "helpUrl": "https://qes.dev/contact",
          "webhookTopics": [
            "device.connected",
            "qes.state.changed"
          ]
        }
      },
      "TenantConfigPatchExample": {
        "value": {
          "branding": {
            "name": "Medentic"
          },
          "helpUrl": "https://qes.dev/contact"
        }
      },
      "CreateApiKeyRequestExample": {
        "value": {
          "label": "production",
          "allowedOperations": [
            "sign.xml",
            "devices.read"
          ],
          "allowedIpRanges": [
            "203.0.113.0/24"
          ]
        }
      },
      "ApiKeyWithSecretExample": {
        "value": {
          "id": "8fdfc5b1-e9f2-4275-a759-5272458f4de7",
          "label": "production",
          "createdAt": "2026-04-04T10:00:00Z",
          "lastUsedAt": null,
          "allowedOperations": [
            "sign.xml",
            "devices.read"
          ],
          "allowedIpRanges": [
            "203.0.113.0/24"
          ],
          "disabled": false,
          "secret": "qes_live_xxxxxxxxx"
        }
      },
      "HealthStatusExample": {
        "value": {
          "status": "ok",
          "service": "api",
          "checkedAt": "2026-04-04T10:00:00Z",
          "details": {
            "latencyMs": 12
          }
        }
      }
    },
    "schemas": {
      "XmlSigningRequest": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "qesId": {
            "type": "string",
            "format": "uuid",
            "description": "Identifier of the target QES certificate or profile."
          },
          "xml": {
            "type": "string"
          },
          "profile": {
            "type": "string",
            "default": "XAdES_BASELINE_B"
          },
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "providerHint": {
            "type": "string"
          },
          "options": {
            "$ref": "#/components/schemas/XmlSigningOptions"
          }
        },
        "required": [
          "id",
          "xml"
        ]
      },
      "XmlSigningOptions": {
        "type": "object",
        "properties": {
          "digestAlgorithm": {
            "type": "string",
            "default": "sha256"
          },
          "canonicalization": {
            "type": "string",
            "default": "c14n"
          }
        },
        "additionalProperties": true
      },
      "XmlSigningResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "signedXml": {
            "type": "string"
          },
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "completedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "signedXml"
        ]
      },
      "TunnelRequest": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "qesId": {
            "type": "string",
            "format": "uuid"
          },
          "method": {
            "type": "string",
            "enum": [
              "GET",
              "POST",
              "PUT",
              "PATCH",
              "DELETE"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "dataBinary": {
            "type": "string",
            "description": "Base64-encoded payload for local execution."
          }
        },
        "required": [
          "id",
          "method",
          "url"
        ]
      },
      "TunnelResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "integer"
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "responseBinary": {
            "type": "string",
            "description": "Base64-encoded response payload."
          }
        },
        "required": [
          "id",
          "status"
        ]
      },
      "Device": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "online",
              "offline",
              "busy"
            ]
          },
          "platform": {
            "type": "string",
            "enum": [
              "windows",
              "macos",
              "linux"
            ]
          },
          "appVersion": {
            "type": "string"
          },
          "lastSeenAt": {
            "type": "string",
            "format": "date-time"
          },
          "qesCertificates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/QesCertificate"
            }
          }
        },
        "required": [
          "id",
          "status",
          "platform"
        ]
      },
      "QesCertificate": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "label": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "connected",
              "disconnected",
              "expired",
              "locked",
              "assigned",
              "unassigned"
            ]
          },
          "validTo": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "label",
          "state"
        ]
      },
      "DiagnosticsRequest": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "scope": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "drivers",
                "token",
                "network",
                "socket"
              ]
            }
          }
        }
      },
      "DiagnosticsResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "result": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "deviceId",
          "result"
        ]
      },
      "DeviceLog": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "logData": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "deviceId",
          "createdAt"
        ]
      },
      "WebhookUpsertRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "hmacSecret": {
            "type": "string"
          },
          "retryPolicy": {
            "$ref": "#/components/schemas/RetryPolicy"
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        },
        "required": [
          "url"
        ]
      },
      "RetryPolicy": {
        "type": "object",
        "properties": {
          "maxRetries": {
            "type": "integer",
            "minimum": 0,
            "default": 3
          }
        }
      },
      "WebhookSubscription": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "topic": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "active": {
            "type": "boolean"
          },
          "retryPolicy": {
            "$ref": "#/components/schemas/RetryPolicy"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "topic",
          "url",
          "active"
        ]
      },
      "WebhookLog": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "eventName": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "httpStatus": {
            "type": "integer"
          },
          "attempts": {
            "type": "integer"
          },
          "lastAttemptAt": {
            "type": "string",
            "format": "date-time"
          },
          "payload": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "id",
          "eventName",
          "status",
          "attempts"
        ]
      },
      "WebhookEventEnvelope": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "event": {
            "type": "string"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "tenantId": {
            "type": "string"
          },
          "deviceId": {
            "type": "string",
            "format": "uuid"
          },
          "qesId": {
            "type": "string",
            "format": "uuid"
          },
          "payload": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "id",
          "event",
          "occurredAt",
          "payload"
        ]
      },
      "TenantConfig": {
        "type": "object",
        "properties": {
          "branding": {
            "type": "object",
            "additionalProperties": true
          },
          "termsUrl": {
            "type": "string",
            "format": "uri"
          },
          "helpUrl": {
            "type": "string",
            "format": "uri"
          },
          "webhookTopics": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "additionalProperties": true
      },
      "TenantConfigPatch": {
        "type": "object",
        "properties": {
          "branding": {
            "type": "object",
            "additionalProperties": true
          },
          "termsUrl": {
            "type": "string",
            "format": "uri"
          },
          "helpUrl": {
            "type": "string",
            "format": "uri"
          }
        },
        "additionalProperties": true
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "label": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastUsedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "allowedOperations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "allowedIpRanges": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "disabled": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "label",
          "createdAt"
        ]
      },
      "ApiKeyWithSecret": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiKey"
          },
          {
            "type": "object",
            "properties": {
              "secret": {
                "type": "string",
                "description": "Only returned when the key is created."
              }
            },
            "required": [
              "secret"
            ]
          }
        ]
      },
      "CreateApiKeyRequest": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string"
          },
          "allowedOperations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "allowedIpRanges": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "label"
        ]
      },
      "HealthStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "error"
            ]
          },
          "service": {
            "type": "string"
          },
          "checkedAt": {
            "type": "string",
            "format": "date-time"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "required": [
          "status",
          "service"
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "requestId": {
                "type": "string",
                "format": "uuid"
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
