{
  "openapi": "3.1.0",
  "info": {
    "title": "SharePrinter 打印队列 API",
    "version": "1.0.0",
    "description": "局域网标签打印队列服务。ERP/App 通过 URL 创建打印任务，Windows Agent 短轮询领取并打印。除 GET /healthz 外，所有 /v1 接口都需要 X-API-Key 请求头。"
  },
  "servers": [
    {
      "url": "/",
      "description": "当前服务端"
    }
  ],
  "tags": [
    {
      "name": "System",
      "description": "健康检查"
    },
    {
      "name": "Config",
      "description": "运行配置"
    },
    {
      "name": "Agents",
      "description": "Agent 注册、心跳与列表"
    },
    {
      "name": "Jobs",
      "description": "打印任务"
    },
    {
      "name": "Printers",
      "description": "打印机"
    },
    {
      "name": "Stats",
      "description": "统计"
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "健康检查",
        "security": [],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "example": {
                  "status": "ok"
                }
              }
            }
          }
        }
      }
    },
    "/v1/config": {
      "get": {
        "tags": [
          "Config"
        ],
        "summary": "查询运行配置",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfigResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Config"
        ],
        "summary": "局部更新运行配置",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConfigPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "更新后的配置与 revision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfigResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agents/register": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "注册或更新 Agent",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentRegisterRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRegisterResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agents/heartbeat": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "心跳、打印机状态与能力",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HeartbeatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HeartbeatResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agents": {
      "get": {
        "tags": [
          "Agents"
        ],
        "summary": "Agent 列表与在线状态",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agents/{agent_id}/jobs/next": {
      "get": {
        "tags": [
          "Jobs"
        ],
        "summary": "领取下一任务（无任务 204）",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "agent_id",
            "in": "path",
            "required": true,
            "description": "Agent ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "已领取任务",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NextJobResponse"
                }
              }
            }
          },
          "204": {
            "description": "队列为空"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs": {
      "get": {
        "tags": [
          "Jobs"
        ],
        "summary": "任务列表",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "任务状态过滤（queued/leased/processing/submitted/failed/unknown/canceled）",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "agent_id",
            "in": "query",
            "required": false,
            "description": "Agent ID 精确匹配",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "printer_id",
            "in": "query",
            "required": false,
            "description": "打印机 ID 精确匹配",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "remote_ref",
            "in": "query",
            "required": false,
            "description": "业务单号精确匹配",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "每页数量，默认 20，最大 100",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "偏移量，默认 0",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobListResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Jobs"
        ],
        "summary": "创建打印任务（幂等）",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateJobRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "任务已创建",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "200": {
            "description": "幂等命中，返回既有任务",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs/{job_id}": {
      "get": {
        "tags": [
          "Jobs"
        ],
        "summary": "任务详情与事件链",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "description": "任务 ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobDetail"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/jobs/{job_id}/status": {
      "post": {
        "tags": [
          "Jobs"
        ],
        "summary": "Agent 回传任务状态",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "description": "任务 ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JobStatusReport"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/printers": {
      "get": {
        "tags": [
          "Printers"
        ],
        "summary": "打印机列表与状态",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrinterListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/printers/{agent_id}/{printer_id}": {
      "patch": {
        "tags": [
          "Printers"
        ],
        "summary": "修改 ERP 管理的打印机字段",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "agent_id",
            "in": "path",
            "required": true,
            "description": "Agent ID",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "printer_id",
            "in": "path",
            "required": true,
            "description": "Printer ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PrinterPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Printer"
                }
              }
            }
          },
          "400": {
            "description": "Bad request / validation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Printers"
        ],
        "summary": "删除打印机记录（Agent 本地停用时调用）",
        "description": "Agent 在本地停用打印机后调用此接口移除服务端记录；重新启用后下一次心跳会重新注册。ERP 一般不需要直接调用。",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "agent_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "printer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "已删除"
          },
          "401": {
            "description": "缺少或错误的 API Key"
          },
          "404": {
            "description": "打印机不存在"
          }
        }
      }
    },
    "/v1/stats": {
      "get": {
        "tags": [
          "Stats"
        ],
        "summary": "任务/Agent/打印机计数",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stats"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "服务级共享密钥，至少 32 字符"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "UNAUTHORIZED",
                  "VALIDATION_ERROR",
                  "NOT_FOUND",
                  "CONFLICT",
                  "ATTEMPT_MISMATCH",
                  "INVALID_STATE_TRANSITION",
                  "INTERNAL_ERROR"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "RuntimeConfig": {
        "type": "object",
        "properties": {
          "retention_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          },
          "agent_offline_seconds": {
            "type": "integer",
            "minimum": 15,
            "maximum": 3600
          },
          "lease_seconds": {
            "type": "integer",
            "minimum": 10,
            "maximum": 600
          },
          "poll_interval_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 60
          },
          "job_max_age_hours": {
            "type": "integer",
            "minimum": 0,
            "maximum": 8760
          },
          "cleanup_enabled": {
            "type": "boolean"
          }
        }
      },
      "ConfigResponse": {
        "type": "object",
        "properties": {
          "revision": {
            "type": "integer",
            "format": "int64"
          },
          "config": {
            "$ref": "#/components/schemas/RuntimeConfig"
          }
        }
      },
      "ConfigPatch": {
        "type": "object",
        "properties": {
          "retention_days": {
            "type": "integer"
          },
          "agent_offline_seconds": {
            "type": "integer"
          },
          "lease_seconds": {
            "type": "integer"
          },
          "poll_interval_seconds": {
            "type": "integer"
          },
          "job_max_age_hours": {
            "type": "integer"
          },
          "cleanup_enabled": {
            "type": "boolean"
          }
        }
      },
      "AgentRegisterRequest": {
        "type": "object",
        "required": [
          "agent_id",
          "machine_id"
        ],
        "properties": {
          "agent_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "version": {
            "type": "string"
          }
        }
      },
      "AgentRegisterResponse": {
        "type": "object",
        "properties": {
          "agent_id": {
            "type": "string"
          },
          "server_time": {
            "type": "string",
            "format": "date-time"
          },
          "config_revision": {
            "type": "integer",
            "format": "int64"
          },
          "config": {
            "$ref": "#/components/schemas/RuntimeConfig"
          }
        }
      },
      "PrinterReport": {
        "type": "object",
        "required": [
          "printer_id",
          "state"
        ],
        "properties": {
          "printer_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "online",
              "offline",
              "paused",
              "paper_out",
              "error",
              "unknown"
            ]
          },
          "message": {
            "type": "string"
          },
          "queue_jobs": {
            "type": "integer"
          },
          "display_name": {
            "type": "string"
          },
          "local_name": {
            "type": "string"
          },
          "driver": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "dpi": {
            "type": "integer"
          },
          "label_width_mm": {
            "type": "number"
          },
          "label_height_mm": {
            "type": "number"
          },
          "gap_mm": {
            "type": "number"
          },
          "offset_x_mm": {
            "type": "number"
          },
          "offset_y_mm": {
            "type": "number"
          },
          "enabled": {
            "type": "boolean",
            "description": "仅在打印机首次注册时使用"
          },
          "default_overflow_policy": {
            "type": "string",
            "enum": [
              "auto",
              "none",
              "fit",
              "tile"
            ],
            "description": "仅在打印机首次注册时使用"
          }
        }
      },
      "HeartbeatRequest": {
        "type": "object",
        "required": [
          "agent_id"
        ],
        "properties": {
          "agent_id": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "spooler_ok": {
            "type": "boolean"
          },
          "printers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PrinterReport"
            }
          }
        }
      },
      "HeartbeatResponse": {
        "type": "object",
        "properties": {
          "server_time": {
            "type": "string",
            "format": "date-time"
          },
          "config_revision": {
            "type": "integer",
            "format": "int64"
          },
          "config": {
            "$ref": "#/components/schemas/RuntimeConfig"
          }
        }
      },
      "JobOptions": {
        "type": "object",
        "properties": {
          "copies": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1
          },
          "rotate": {
            "type": "integer",
            "enum": [
              0,
              90,
              180,
              270
            ],
            "default": 0
          }
        }
      },
      "CreateJobRequest": {
        "type": "object",
        "required": [
          "agent_id",
          "printer_id",
          "source_url"
        ],
        "properties": {
          "idempotency_key": {
            "type": "string",
            "maxLength": 200
          },
          "agent_id": {
            "type": "string"
          },
          "printer_id": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri",
            "description": "http/https，Agent 可访问"
          },
          "overflow_policy": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "auto",
              "none",
              "fit",
              "tile",
              null
            ],
            "description": "null 表示使用打印机默认值"
          },
          "remote_ref": {
            "type": "string",
            "maxLength": 200
          },
          "options": {
            "$ref": "#/components/schemas/JobOptions"
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string"
          },
          "idempotency_key": {
            "type": "string"
          },
          "agent_id": {
            "type": "string"
          },
          "printer_id": {
            "type": "string"
          },
          "source_url": {
            "type": "string"
          },
          "overflow_policy": {
            "type": "string"
          },
          "remote_ref": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "leased",
              "processing",
              "submitted",
              "failed",
              "unknown",
              "canceled"
            ]
          },
          "attempt_id": {
            "type": "string"
          },
          "attempt_count": {
            "type": "integer"
          },
          "retryable": {
            "type": "boolean"
          },
          "error_code": {
            "type": "string"
          },
          "error_message": {
            "type": "string"
          },
          "reprint_of": {
            "type": "string"
          },
          "options": {
            "$ref": "#/components/schemas/JobOptions"
          },
          "lease_until": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "submitted_at": {
            "type": "string",
            "format": "date-time"
          },
          "spooler_job_id": {
            "type": "integer",
            "description": "Windows spooler job id（StartDoc 返回值）"
          },
          "spooler_state": {
            "type": "string",
            "enum": [
              "printed",
              "completed",
              "printing",
              "queued",
              "error",
              "offline",
              "paper_out",
              "paused",
              "blocked",
              "user_intervention",
              "timeout",
              "unknown"
            ],
            "description": "打印队列状态，仅供展示，不改变任务状态"
          },
          "spooler_message": {
            "type": "string",
            "description": "队列或驱动给出的状态说明"
          },
          "spooler_completed_at": {
            "type": "string",
            "format": "date-time",
            "description": "队列报告完成/打印的时间"
          }
        }
      },
      "JobEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "job_id": {
            "type": "string"
          },
          "attempt_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "JobDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Job"
          },
          {
            "type": "object",
            "properties": {
              "events": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/JobEvent"
                }
              }
            }
          }
        ]
      },
      "JobListResponse": {
        "type": "object",
        "properties": {
          "jobs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Job"
            }
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          }
        }
      },
      "NextJobResponse": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string"
          },
          "attempt_id": {
            "type": "string"
          },
          "lease_seconds": {
            "type": "integer"
          },
          "printer_id": {
            "type": "string"
          },
          "source_url": {
            "type": "string"
          },
          "overflow_policy": {
            "type": "string"
          },
          "options": {
            "$ref": "#/components/schemas/JobOptions"
          }
        }
      },
      "JobStatusReport": {
        "type": "object",
        "required": [
          "attempt_id",
          "status"
        ],
        "properties": {
          "attempt_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "submitted",
              "failed",
              "unknown"
            ]
          },
          "error_code": {
            "type": "string"
          },
          "error_message": {
            "type": "string"
          },
          "retryable": {
            "type": "boolean"
          },
          "spooler_job_id": {
            "type": "integer"
          },
          "spooler_state": {
            "type": "string",
            "enum": [
              "printed",
              "completed",
              "printing",
              "queued",
              "error",
              "offline",
              "paper_out",
              "paused",
              "blocked",
              "user_intervention",
              "timeout",
              "unknown"
            ]
          },
          "spooler_message": {
            "type": "string"
          },
          "spooler_completed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Printer": {
        "type": "object",
        "properties": {
          "agent_id": {
            "type": "string"
          },
          "printer_id": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          },
          "local_name": {
            "type": "string"
          },
          "driver": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "dpi": {
            "type": "integer"
          },
          "label_width_mm": {
            "type": "number"
          },
          "label_height_mm": {
            "type": "number"
          },
          "gap_mm": {
            "type": "number"
          },
          "offset_x_mm": {
            "type": "number"
          },
          "offset_y_mm": {
            "type": "number"
          },
          "default_overflow_policy": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "runtime_state": {
            "type": "string"
          },
          "runtime_message": {
            "type": "string"
          },
          "status_updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "agent_online": {
            "type": "boolean"
          },
          "agent_last_seen": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PrinterListResponse": {
        "type": "object",
        "properties": {
          "printers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Printer"
            }
          }
        }
      },
      "PrinterPatch": {
        "type": "object",
        "properties": {
          "display_name": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "default_overflow_policy": {
            "type": "string",
            "enum": [
              "auto",
              "none",
              "fit",
              "tile"
            ]
          }
        }
      },
      "Agent": {
        "type": "object",
        "properties": {
          "agent_id": {
            "type": "string"
          },
          "machine_id": {
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "online": {
            "type": "boolean"
          },
          "last_seen": {
            "type": "string",
            "format": "date-time"
          },
          "printer_count": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AgentListResponse": {
        "type": "object",
        "properties": {
          "agents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Agent"
            }
          }
        }
      },
      "Stats": {
        "type": "object",
        "properties": {
          "jobs_total": {
            "type": "integer"
          },
          "jobs_by_status": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "agents_total": {
            "type": "integer"
          },
          "agents_online": {
            "type": "integer"
          },
          "printers_total": {
            "type": "integer"
          },
          "printers_enabled": {
            "type": "integer"
          }
        }
      }
    }
  }
}
