{
  "openapi": "3.1.1",
  "info": {
    "title": "Hardware Inventory Cloud Platform API",
    "version": "1.1.0",
    "description": "Authentication, preassigned devices and hardware snapshot storage for Hardware Inventory. The desktop supports offline JSON capture and authenticated publishing. Devices are provisioned by administrators; uploads never create devices."
  },
  "servers": [
    {
      "url": "https://cooljhw.tdns.pro",
      "description": "Cloud Platform"
    },
    {
      "url": "http://127.0.0.1:1481",
      "description": "Local development"
    }
  ],
  "tags": [
    {
      "name": "Authentication"
    },
    {
      "name": "Health"
    },
    {
      "name": "Inventory"
    },
    {
      "name": "Windows keys"
    },
    {
      "name": "Administration"
    }
  ],
  "paths": {
    "/admin/api/options": {
      "get": {
        "operationId": "adminOptions",
        "tags": ["Administration"],
        "summary": "Discover the browser admin login mode",
        "responses": {
          "200": {
            "description": "Password login options",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["mode", "name"],
                  "properties": {
                    "mode": { "const": "password" },
                    "name": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/admin/api/login": {
      "post": {
        "operationId": "adminLogin",
        "tags": ["Administration"],
        "summary": "Sign in as an administrator with a password",
        "description": "Independent of the desktop login mode. Requires same-origin verification; no CSRF token is needed for login. On success sets a Secure, HttpOnly, SameSite=Strict __Host-hwinv-admin cookie with Path=/; session expires after 20 minutes. No cookie token is included in JSON.",
        "parameters": [
          { "$ref": "#/components/parameters/AdminOrigin" },
          { "$ref": "#/components/parameters/AdminRequestedWith" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/PasswordLogin" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session, CSRF token and Set-Cookie",
            "headers": { "Set-Cookie": { "schema": { "type": "string" } } },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AdminSession" }
              }
            }
          },
          "400": { "description": "Invalid JSON" },
          "401": { "description": "Credentials not accepted" },
          "403": { "description": "Origin or request header rejected" },
          "429": { "description": "Login rate limit exceeded" }
        }
      }
    },
    "/admin/api/session": {
      "get": {
        "operationId": "adminSession",
        "tags": ["Administration"],
        "summary": "Get the current admin session and CSRF token",
        "security": [{ "adminCookie": [] }],
        "responses": {
          "200": {
            "description": "Current session",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AdminSession" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "description": "Administrator access required" }
        }
      }
    },
    "/admin/api/logout": {
      "post": {
        "operationId": "adminLogout",
        "tags": ["Administration"],
        "summary": "Revoke the admin session",
        "security": [{ "adminCookie": [] }],
        "parameters": [
          { "$ref": "#/components/parameters/AdminOrigin" },
          { "$ref": "#/components/parameters/AdminRequestedWith" },
          { "$ref": "#/components/parameters/AdminCSRF" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EmptyObject" }
            }
          }
        },
        "responses": {
          "204": { "description": "Session revoked and cookie cleared" },
          "400": { "description": "Invalid JSON" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "description": "Request verification failed" }
        }
      }
    },
    "/admin/api/users": {
      "get": {
        "operationId": "adminListUsers",
        "tags": ["Administration"],
        "summary": "List up to 200 users and configured PIN length",
        "security": [{ "adminCookie": [] }],
        "responses": {
          "200": {
            "description": "User list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["users", "pinLength"],
                  "properties": {
                    "users": {
                      "type": "array",
                      "maxItems": 200,
                      "items": { "$ref": "#/components/schemas/AdminUser" }
                    },
                    "pinLength": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 10
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "description": "Administrator access required" }
        }
      },
      "post": {
        "operationId": "adminCreateUser",
        "tags": ["Administration"],
        "summary": "Create an operator with a PIN",
        "description": "The PIN is a string of exactly the configured number of digits; preserve leading zeros. This operation cannot grant administrator rights.",
        "security": [{ "adminCookie": [] }],
        "parameters": [
          { "$ref": "#/components/parameters/AdminOrigin" },
          { "$ref": "#/components/parameters/AdminRequestedWith" },
          { "$ref": "#/components/parameters/AdminCSRF" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AdminCreateUser" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created operator",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["user"],
                  "properties": {
                    "user": { "$ref": "#/components/schemas/AdminUser" }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid fields or PIN length" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": {
            "description": "Request verification or admin access failed"
          },
          "409": { "description": "Duplicate user, email or PIN" }
        }
      }
    },
    "/admin/api/windows-keys": {
      "get": {
        "operationId": "adminListWindowsKeys",
        "tags": ["Administration"],
        "summary": "List up to 200 masked Windows keys",
        "description": "Only the last five characters are returned; existing full keys are never revealed.",
        "security": [{ "adminCookie": [] }],
        "responses": {
          "200": {
            "description": "Masked key list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["keys"],
                  "properties": {
                    "keys": {
                      "type": "array",
                      "maxItems": 200,
                      "items": {
                        "$ref": "#/components/schemas/AdminWindowsKey"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "description": "Administrator access required" }
        }
      },
      "post": {
        "operationId": "adminCreateWindowsKey",
        "tags": ["Administration"],
        "summary": "Add a Windows product key",
        "description": "Keys are encrypted at rest; the response does not reveal the key.",
        "security": [{ "adminCookie": [] }],
        "parameters": [
          { "$ref": "#/components/parameters/AdminOrigin" },
          { "$ref": "#/components/parameters/AdminRequestedWith" },
          { "$ref": "#/components/parameters/AdminCSRF" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AdminCreateWindowsKey" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status"],
                  "properties": { "status": { "const": "created" } }
                }
              }
            }
          },
          "400": { "description": "Invalid fields" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": {
            "description": "Request verification or admin access failed"
          },
          "409": { "description": "Duplicate key" }
        }
      }
    },
    "/api/v1/auth/options": {
      "get": {
        "operationId": "getLoginOptions",
        "tags": ["Authentication"],
        "summary": "Discover the login method before opening the desktop modal",
        "responses": {
          "200": {
            "description": "The login method currently selected by the server",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginOptions"
                },
                "example": {
                  "mode": "pin",
                  "name": "Cloud Platform",
                  "pinLength": 4
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/login": {
      "post": {
        "operationId": "login",
        "tags": ["Authentication"],
        "summary": "Authenticate with the method returned by discovery",
        "description": "A PIN identifies the user without a username. Treat PINs as strings to preserve leading zeros. Sessions last 20 minutes; the desktop extends the same session every 15 minutes while open. A mode changed since discovery returns 409. The server allows a global burst of ten login attempts and then one attempt per second. Request bodies are limited to 4096 bytes. Supplying an installation key binds the session to that installation and replaces its previous sessions.",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstallationKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/PINLogin"
                  },
                  {
                    "$ref": "#/components/schemas/PasswordLogin"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authenticated user and opaque Bearer token; keep the token private",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON, unknown fields or trailing content",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credentials were not accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Login method changed; discover the method again and reopen Login",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type must be application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many login attempts",
            "headers": {
              "Retry-After": {
                "description": "Seconds before retrying",
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/session": {
      "get": {
        "operationId": "getSession",
        "tags": ["Authentication"],
        "summary": "Validate the current session",
        "description": "Expired, revoked and disabled-user sessions are rejected. This endpoint does not extend the expiry.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current user and session expiry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "operationId": "logout",
        "tags": ["Authentication"],
        "summary": "Revoke the session token",
        "description": "Deletes the session. Revocation is idempotent for a correctly formed Bearer token. No request body is needed.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "204": {
            "description": "Token revoked; empty response body"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/reset": {
      "post": {
        "operationId": "resetInstallationSessions",
        "tags": ["Authentication"],
        "summary": "Revoke abandoned sessions on application startup",
        "description": "Uses the installation's persistent random revocation key. Deletes only sessions bound to that installation. The key cannot log in, retrieve a session or extend a session. The desktop starts locked, calls reset on launch, and retries it before login if the startup request failed. No body is needed.",
        "security": [
          {
            "installationKey": []
          }
        ],
        "responses": {
          "204": {
            "description": "Installation's sessions revoked; also returned when none exist"
          },
          "401": {
            "description": "Missing or malformed installation key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "operationId": "getHealth",
        "tags": ["Health"],
        "summary": "Check HTTP service availability",
        "responses": {
          "200": {
            "description": "HTTP service is running",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status"],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    }
                  }
                },
                "example": {
                  "status": "ok"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/extend": {
      "post": {
        "operationId": "extendSession",
        "tags": ["Authentication"],
        "summary": "Extend a valid sliding session without changing its token",
        "description": "Keeps the existing token and advances expiresAt to at least 20 minutes after the request. Expired, revoked and disabled-user sessions cannot extend. The desktop calls this every 15 minutes while running, with five minutes of headroom. No request body is needed.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current user and extended expiry; no new token is issued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/devices/{code}": {
      "get": {
        "operationId": "getDevice",
        "tags": ["Inventory"],
        "summary": "Find a preassigned device code",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Registered device",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Device"
                }
              }
            }
          },
          "401": {
            "description": "Session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unregistered code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/inventories": {
      "post": {
        "operationId": "publishInventory",
        "tags": ["Inventory"],
        "summary": "Publish a saved or live inventory to its preassigned device",
        "description": "Body limit is 8 MiB plus envelope overhead. The inventory deviceID must match deviceCode. UUID is a hardware hint, not the asset key. A different nonempty UUID requires explicit confirmDeviceChange. Equal compact JSON for the same device reuses the previous receipt. PINs, passwords and tokens must not be included in offline files. All authenticated operators share the devices in this single Cloud Platform.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InventoryUpload"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "New snapshot stored",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryReceipt"
                }
              }
            }
          },
          "200": {
            "description": "Identical snapshot already stored",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Invalid inventory",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unregistered device code; no device created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Review and confirm the changed system UUID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Inventory too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Cloud Platform unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/inventories/{id}": {
      "get": {
        "operationId": "downloadInventory",
        "tags": ["Inventory"],
        "summary": "Download the preserved hardware snapshot",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Original inventory document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HardwareInventory"
                }
              }
            }
          },
          "401": {
            "description": "Session required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Snapshot not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/windows-keys/reservations": {
      "post": {
        "operationId": "reserveWindowsKey",
        "tags": ["Windows keys"],
        "summary": "Reserve a Windows product key",
        "description": "Reserved keys have a 30-minute lease. Treat the returned product key as a secret. Applying and assigned keys are not recycled automatically.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WindowsKeyReservationRequest"
              }
            }
          }
        },
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "200": {
            "description": "Key reserved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WindowsKeyReservation"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/windows-keys/reservations/{id}/start": {
      "post": {
        "operationId": "startWindowsKeyReservation",
        "tags": ["Windows keys"],
        "summary": "Mark a reservation as applying",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyObject"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reservation marked applying",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status"],
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/windows-keys/reservations/{id}/complete": {
      "post": {
        "operationId": "completeWindowsKeyReservation",
        "tags": ["Windows keys"],
        "summary": "Report the activation outcome",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WindowsKeyCompletion"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Outcome recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status"],
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/v1/windows-keys/reservations/{id}/release": {
      "post": {
        "operationId": "releaseWindowsKeyReservation",
        "tags": ["Windows keys"],
        "summary": "Release a reserved key",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmptyObject"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Reservation released; empty response body"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "adminCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-hwinv-admin",
        "description": "Secure, HttpOnly, SameSite=Strict admin session cookie. Mutations additionally require the CSRF, Origin and X-Requested-With headers."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Opaque token returned by login; this is not a JWT"
      },
      "installationKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Hardware-Inventory-Client",
        "description": "Persistent random revocation key (32 bytes as unpadded base64url); grants revocation only, no login access"
      }
    },
    "parameters": {
      "AdminOrigin": {
        "name": "Origin",
        "in": "header",
        "required": true,
        "description": "Must match the request host and scheme",
        "schema": { "type": "string" }
      },
      "AdminRequestedWith": {
        "name": "X-Requested-With",
        "in": "header",
        "required": true,
        "schema": { "type": "string", "const": "hardware-inventory-admin" }
      },
      "AdminCSRF": {
        "name": "X-CSRF-Token",
        "in": "header",
        "required": true,
        "description": "Token from the admin login or session response",
        "schema": { "type": "string" }
      },
      "InstallationKey": {
        "name": "X-Hardware-Inventory-Client",
        "in": "header",
        "required": false,
        "description": "Bind this login to one desktop installation for abandoned-session cleanup",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Authentication is missing, malformed, expired or revoked, or the user was disabled",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Cloud Platform is unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "AdminSession": {
        "type": "object",
        "required": ["user", "expiresAt", "csrfToken"],
        "properties": {
          "user": { "$ref": "#/components/schemas/User" },
          "expiresAt": { "type": "integer", "description": "Unix seconds" },
          "csrfToken": {
            "type": "string",
            "description": "Keep in memory; send as X-CSRF-Token for authenticated mutations"
          }
        }
      },
      "AdminUser": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "username": { "type": "string" },
          "name": { "type": "string" },
          "email": { "type": "string" },
          "active": { "type": "boolean" },
          "isAdmin": { "type": "boolean" },
          "hasPIN": { "type": "boolean" }
        }
      },
      "AdminCreateUser": {
        "type": "object",
        "required": ["username", "name", "email", "pin"],
        "properties": {
          "username": { "type": "string" },
          "name": { "type": "string" },
          "email": { "type": "string" },
          "pin": {
            "type": "string",
            "pattern": "^[0-9]+$",
            "description": "Exactly the configured PIN length; leading zeros are significant",
            "writeOnly": true
          }
        }
      },
      "AdminWindowsKey": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "product": { "type": "string" },
          "editionId": { "type": "string" },
          "channel": { "type": "string" },
          "partialKey": {
            "type": "string",
            "description": "Last five characters only"
          },
          "status": {
            "type": "string",
            "enum": ["available", "reserved", "applying", "activated", "held"]
          },
          "createdAt": { "type": "integer", "description": "Unix seconds" },
          "reservedUntil": { "type": "integer", "description": "Unix seconds" }
        }
      },
      "AdminCreateWindowsKey": {
        "type": "object",
        "required": ["product", "editionId", "channel", "productKey"],
        "properties": {
          "product": {
            "type": "string",
            "enum": [
              "Windows 10",
              "Windows 11",
              "Windows Server 2016",
              "Windows Server 2019",
              "Windows Server 2022",
              "Windows Server 2025"
            ]
          },
          "editionId": { "type": "string" },
          "channel": { "type": "string", "enum": ["Retail", "Volume:MAK"] },
          "productKey": { "type": "string", "writeOnly": true }
        }
      },
      "LoginOptions": {
        "type": "object",
        "required": ["mode", "name"],
        "properties": {
          "mode": {
            "type": "string",
            "enum": ["pin", "password"]
          },
          "name": {
            "type": "string",
            "const": "Cloud Platform"
          },
          "pinLength": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 4,
            "description": "Number of masked PIN input cells. Returned for PIN mode; configured by the server and does not change existing account credentials."
          }
        }
      },
      "PINLogin": {
        "type": "object",
        "additionalProperties": false,
        "required": ["mode", "pin"],
        "properties": {
          "mode": {
            "type": "string",
            "const": "pin"
          },
          "pin": {
            "type": "string",
            "pattern": "^[0-9]{1,10}$",
            "writeOnly": true
          }
        }
      },
      "PasswordLogin": {
        "type": "object",
        "additionalProperties": false,
        "required": ["mode", "username", "password"],
        "properties": {
          "mode": {
            "type": "string",
            "const": "password"
          },
          "username": {
            "type": "string",
            "minLength": 1,
            "description": "Case-insensitive account name"
          },
          "password": {
            "type": "string",
            "writeOnly": true,
            "description": "Account password; stored passwords are 8 to 72 UTF-8 bytes"
          }
        }
      },
      "User": {
        "type": "object",
        "required": ["id", "username", "name", "email"],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "username": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "description": "User's display name"
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "Session": {
        "type": "object",
        "required": ["user", "expiresAt"],
        "properties": {
          "user": {
            "$ref": "#/components/schemas/User"
          },
          "expiresAt": {
            "type": "integer",
            "format": "int64",
            "description": "Expiry as Unix seconds (UTC)"
          }
        }
      },
      "LoginResult": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Session"
          },
          {
            "type": "object",
            "required": ["token"],
            "properties": {
              "token": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_-]{43}$",
                "description": "32 random bytes encoded as unpadded base64url"
              }
            }
          }
        ]
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "Device": {
        "type": "object",
        "required": ["id", "code", "name"],
        "properties": {
          "id": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "sguid": {
            "type": "string"
          }
        }
      },
      "InventoryReceipt": {
        "type": "object",
        "required": [
          "id",
          "device",
          "sha256",
          "receivedAt",
          "duplicate",
          "identityChanged"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "device": {
            "$ref": "#/components/schemas/Device"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "receivedAt": {
            "type": "integer"
          },
          "duplicate": {
            "type": "boolean"
          },
          "identityChanged": {
            "type": "boolean"
          }
        }
      },
      "HardwareInventory": {
        "type": "object",
        "required": ["deviceID"],
        "properties": {
          "deviceID": {
            "type": "string",
            "description": "Preassigned device code; distinct from the internal Cloud device id"
          },
          "SGUID": {
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "APPVER": {
            "type": "string"
          },
          "collectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "OS": {
            "type": "object"
          },
          "Mainboard": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "Cpu": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "Memory": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "Gpu": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "HardDrives": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "NetworkInterfaces": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "RaidController": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "PSU": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "Monitors": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "Batteries": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "additionalProperties": true
      },
      "InventoryUpload": {
        "type": "object",
        "additionalProperties": false,
        "required": ["deviceCode", "inventory"],
        "properties": {
          "deviceCode": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "inventory": {
            "$ref": "#/components/schemas/HardwareInventory"
          },
          "confirmDeviceChange": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "WindowsKeyReservationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "deviceCode",
          "machineId",
          "productName",
          "editionId",
          "currentBuild"
        ],
        "properties": {
          "deviceCode": {
            "type": "string"
          },
          "machineId": {
            "type": "string"
          },
          "productName": {
            "type": "string"
          },
          "editionId": {
            "type": "string"
          },
          "currentBuild": {
            "type": "integer"
          }
        }
      },
      "WindowsKeyReservation": {
        "type": "object",
        "required": [
          "id",
          "productKey",
          "partialKey",
          "expiresAt",
          "status",
          "product",
          "editionId",
          "channel"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "productKey": {
            "type": "string",
            "description": "Sensitive product key; do not log or persist in inventory snapshots."
          },
          "partialKey": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "product": {
            "type": "string"
          },
          "editionId": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "expiresAt": {
            "type": "integer",
            "format": "int64",
            "description": "Reserved lease expiry as Unix seconds (UTC); the lease lasts 30 minutes."
          }
        }
      },
      "WindowsKeyCompletion": {
        "type": "object",
        "additionalProperties": false,
        "required": ["outcome", "keyInstalled"],
        "properties": {
          "outcome": {
            "type": "string",
            "enum": ["activated", "cancelled", "unconfirmed"]
          },
          "keyInstalled": {
            "type": "boolean"
          }
        }
      },
      "EmptyObject": {
        "type": "object",
        "additionalProperties": false,
        "maxProperties": 0
      }
    }
  }
}
