{
  "openapi": "3.1.0",
  "info": {
    "title": "UPI-GIT5 API",
    "version": "1.0.0",
    "description": "UPI-GIT5 批量提链、提链 CDK 租户会话及自动支付接口。公网使用 HTTPS，端口 443。"
  },
  "servers": [
    {
      "url": "https://upi.agiapi.top",
      "description": "生产服务（HTTPS，TCP 443）",
      "x-protocol": "HTTPS",
      "x-port": 443
    }
  ],
  "tags": [
    {"name": "Service", "description": "服务配置和统计"},
    {"name": "Link CDK", "description": "提链 CDK 与租户会话"},
    {"name": "Batch", "description": "批量提链和任务状态"},
    {"name": "Payment", "description": "自动支付配置与提交"},
    {"name": "Admin", "description": "提链 CDK 管理"}
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": ["Service"],
        "summary": "服务健康与全站统计",
        "operationId": "getHealth",
        "responses": {
          "200": {"description": "服务正常", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/HealthResponse"}}}}
        }
      }
    },
    "/api/config": {
      "get": {
        "tags": ["Service"],
        "summary": "读取服务配置",
        "operationId": "getConfig",
        "responses": {"200": {"description": "服务配置", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}}
      }
    },
    "/api/recent-results": {
      "get": {
        "tags": ["Service"],
        "summary": "读取最近任务结果统计",
        "operationId": "getRecentResults",
        "parameters": [{"name": "hours", "in": "query", "schema": {"type": "number", "default": 12, "minimum": 0.0167}}],
        "responses": {
          "200": {"description": "任务结果统计", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"}
        }
      }
    },
    "/api/fingerprint-stats": {
      "get": {
        "tags": ["Service"],
        "summary": "读取 Firefox 指纹统计",
        "operationId": "getFingerprintStats",
        "responses": {"200": {"description": "指纹统计", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}}
      }
    },
    "/api/link-cdk/status": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "验证提链 CDK 并读取余额",
        "operationId": "getLinkCdkStatus",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkCodeRequest"}}}},
        "responses": {
          "200": {"description": "CDK 状态", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkStatusResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/link-cdk/session": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "创建提链 CDK 租户会话",
        "operationId": "createLinkCdkSession",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkCodeRequest"}}}},
        "responses": {
          "200": {"description": "会话已创建", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkCdkSessionResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/link-cdk/session/logout": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "注销提链 CDK 租户会话",
        "operationId": "logoutLinkCdkSession",
        "security": [{"LinkCdkSession": []}],
        "responses": {"200": {"$ref": "#/components/responses/Ok"}}
      }
    },
    "/api/link-cdk/fuse": {
      "post": {
        "tags": ["Link CDK"],
        "summary": "融合提链 CDK 额度",
        "description": "来源 CDK 的全部剩余额度转入目标 CDK。不可融合 CDK 可以接收额度，但不能作为来源转出额度。",
        "operationId": "fuseLinkCdk",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["target_code", "source_code"], "properties": {"target_code": {"type": "string"}, "source_code": {"type": "string"}}}}}},
        "responses": {
          "200": {"description": "融合完成", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "409": {"$ref": "#/components/responses/Conflict"}
        }
      }
    },
    "/api/upi-git5/batch": {
      "post": {
        "tags": ["Batch"],
        "summary": "创建 UPI-GIT5 批量任务",
        "operationId": "createUpiGit5Batch",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchCreateRequest"}}}},
        "responses": {
          "202": {"description": "批次已创建", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchCreateResponse"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "409": {"$ref": "#/components/responses/Conflict"},
          "429": {"$ref": "#/components/responses/TooManyRequests"}
        }
      }
    },
    "/api/upi-git5/batch/{batch_id}": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取批次完整详情",
        "operationId": "getUpiGit5Batch",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/BatchId"}],
        "responses": {
          "200": {"description": "批次详情", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchSnapshot"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/upi-git5/batch/{batch_id}/progress": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取批次轻量进度",
        "operationId": "getUpiGit5BatchProgress",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/BatchId"}],
        "responses": {
          "200": {"description": "批次进度", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BatchSnapshot"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout-progress": {
      "get": {
        "tags": ["Batch"],
        "summary": "读取单个任务进度",
        "operationId": "getCheckoutProgress",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/JobIdQuery"}],
        "responses": {
          "200": {"description": "任务快照", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Job"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout-qr": {
      "get": {
        "tags": ["Batch"],
        "summary": "获取任务支付二维码",
        "operationId": "getCheckoutQr",
        "security": [{"LinkCdkSession": []}],
        "parameters": [{"$ref": "#/components/parameters/JobIdQuery"}],
        "responses": {
          "200": {"description": "二维码 PNG", "content": {"image/png": {"schema": {"type": "string", "contentEncoding": "base64"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/checkout-cancel": {
      "post": {
        "tags": ["Batch"],
        "summary": "停止单个任务",
        "operationId": "cancelCheckout",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/JobIdRequest"}}}},
        "responses": {
          "200": {"$ref": "#/components/responses/Ok"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "404": {"$ref": "#/components/responses/NotFound"}
        }
      }
    },
    "/api/payment/status": {
      "get": {
        "tags": ["Payment"],
        "summary": "读取当前租户支付配置",
        "operationId": "getPaymentStatus",
        "security": [{"LinkCdkSession": []}],
        "responses": {
          "200": {"description": "支付配置", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentStatusResponse"}}}},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/configure": {
      "post": {
        "tags": ["Payment"],
        "summary": "保存并登录支付平台 CDK",
        "operationId": "configurePayment",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["provider_id", "cdk"], "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}, "cdk": {"type": "string"}}}}}},
        "responses": {
          "200": {"description": "平台 CDK 已配置", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/payment/settings": {
      "post": {
        "tags": ["Payment"],
        "summary": "切换平台及自动提交开关",
        "operationId": "setPaymentSettings",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["provider_id", "enabled"], "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}, "enabled": {"type": "boolean"}}}}}},
        "responses": {
          "200": {"description": "支付设置已更新", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/clear": {
      "post": {
        "tags": ["Payment"],
        "summary": "清空指定平台支付 CDK",
        "operationId": "clearPaymentCdk",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderRequest"}}}},
        "responses": {
          "200": {"description": "平台 CDK 已清空", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"}
        }
      }
    },
    "/api/payment/quota": {
      "post": {
        "tags": ["Payment"],
        "summary": "刷新支付 CDK 剩余额度",
        "operationId": "refreshPaymentQuota",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderRequest"}}}},
        "responses": {
          "200": {"description": "支付额度已刷新", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaymentProviderStatus"}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/payment/manual-submit": {
      "post": {
        "tags": ["Payment"],
        "summary": "批量手动提交未提交支付的任务",
        "operationId": "manualSubmitPayment",
        "security": [{"LinkCdkSession": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["job_ids"], "properties": {"job_ids": {"type": "array", "maxItems": 5000, "items": {"type": "string"}}}}}}},
        "responses": {
          "202": {"description": "任务已进入支付队列", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "provider_id": {"type": "string"}, "queued": {"type": "array", "items": {"type": "string"}}, "skipped": {"type": "array", "items": {"type": "object", "additionalProperties": true}}}}}}},
          "400": {"$ref": "#/components/responses/BadRequest"},
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "502": {"$ref": "#/components/responses/BadGateway"}
        }
      }
    },
    "/api/link-cdk/admin/login": {
      "post": {
        "tags": ["Admin"],
        "summary": "登录提链 CDK 管理后台",
        "operationId": "loginLinkCdkAdmin",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["secret"], "properties": {"secret": {"type": "string"}}}}}},
        "responses": {
          "200": {"description": "管理员会话已创建", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "token": {"type": "string"}, "expires_at": {"type": "number"}}}}}},
          "403": {"$ref": "#/components/responses/Forbidden"},
          "429": {"$ref": "#/components/responses/TooManyRequests"}
        }
      }
    },
    "/api/link-cdk/admin/logout": {
      "post": {
        "tags": ["Admin"],
        "summary": "注销管理员会话",
        "operationId": "logoutLinkCdkAdmin",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "responses": {"200": {"$ref": "#/components/responses/Ok"}}
      }
    },
    "/api/link-cdk/admin/summary": {
      "get": {
        "tags": ["Admin"],
        "summary": "读取 CDK 与并发汇总",
        "operationId": "getLinkCdkAdminSummary",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "responses": {"200": {"description": "管理汇总", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    },
    "/api/link-cdk/admin/cdks": {
      "get": {
        "tags": ["Admin"],
        "summary": "分页查询提链 CDK",
        "operationId": "listLinkCdks",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "parameters": [
          {"name": "page", "in": "query", "schema": {"type": "integer", "default": 1, "minimum": 1}},
          {"name": "page_size", "in": "query", "schema": {"type": "integer", "default": 50, "minimum": 1}},
          {"name": "query", "in": "query", "schema": {"type": "string"}},
          {"name": "status", "in": "query", "schema": {"type": "string"}}
        ],
        "responses": {"200": {"description": "CDK 列表", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    },
    "/api/link-cdk/admin/cdks/generate": {
      "post": {
        "tags": ["Admin"],
        "summary": "批量生成提链 CDK",
        "operationId": "generateLinkCdks",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/GenerateLinkCdksRequest"}}}},
        "responses": {"200": {"description": "CDK 已生成", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    },
    "/api/link-cdk/admin/cdks/{cdk_id}": {
      "parameters": [{"$ref": "#/components/parameters/CdkId"}],
      "patch": {
        "tags": ["Admin"],
        "summary": "更新 CDK 状态、并发或标签",
        "operationId": "updateLinkCdk",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "properties": {"status": {"type": "string", "enum": ["active", "disabled"]}, "concurrency_limit": {"type": "integer", "enum": [10, 20, 30, 50, 100]}, "label": {"type": "string"}}, "minProperties": 1}}}},
        "responses": {"200": {"description": "CDK 已更新", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "404": {"$ref": "#/components/responses/NotFound"}}
      },
      "delete": {
        "tags": ["Admin"],
        "summary": "删除单个提链 CDK",
        "operationId": "deleteLinkCdk",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "responses": {"200": {"description": "CDK 已删除", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "404": {"$ref": "#/components/responses/NotFound"}, "409": {"$ref": "#/components/responses/Conflict"}}
      }
    },
    "/api/link-cdk/admin/cdks/batch-delete": {
      "post": {
        "tags": ["Admin"],
        "summary": "批量删除提链 CDK",
        "operationId": "batchDeleteLinkCdks",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["ids"], "properties": {"ids": {"type": "array", "items": {"type": "string"}}}}}}},
        "responses": {"200": {"description": "批量删除结果", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "409": {"$ref": "#/components/responses/Conflict"}}
      }
    },
    "/api/link-cdk/admin/cdks/{cdk_id}/records": {
      "get": {
        "tags": ["Admin"],
        "summary": "读取 CDK 消耗、成功及融合记录",
        "operationId": "getLinkCdkRecords",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "parameters": [{"$ref": "#/components/parameters/CdkId"}, {"name": "limit", "in": "query", "schema": {"type": "integer", "default": 200, "minimum": 1}}],
        "responses": {"200": {"description": "CDK 记录", "content": {"application/json": {"schema": {"type": "object", "additionalProperties": true}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "404": {"$ref": "#/components/responses/NotFound"}}
      }
    },
    "/api/link-cdk/admin/cdks/{cdk_id}/clear-records": {
      "post": {
        "tags": ["Admin"],
        "summary": "清空指定 CDK 的可清理记录",
        "operationId": "clearLinkCdkRecords",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "parameters": [{"$ref": "#/components/parameters/CdkId"}],
        "responses": {"200": {"$ref": "#/components/responses/Ok"}, "401": {"$ref": "#/components/responses/Unauthorized"}, "404": {"$ref": "#/components/responses/NotFound"}}
      }
    },
    "/api/link-cdk/admin/settings/global-concurrency": {
      "put": {
        "tags": ["Admin"],
        "summary": "动态设置全站并发上限",
        "operationId": "setGlobalConcurrency",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["value"], "properties": {"value": {"type": "integer", "minimum": 1}}}}}},
        "responses": {"200": {"description": "并发设置已更新", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "global_concurrency": {"type": "integer"}}}}}}, "400": {"$ref": "#/components/responses/BadRequest"}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    },
    "/api/tasks/reset": {
      "post": {
        "tags": ["Admin"],
        "summary": "清空服务端当前任务队列",
        "operationId": "resetTasks",
        "security": [{"AdminBearer": []}, {"AdminTokenHeader": []}],
        "responses": {"200": {"$ref": "#/components/responses/Ok"}, "401": {"$ref": "#/components/responses/Unauthorized"}}
      }
    }
  },
  "components": {
    "securitySchemes": {
      "LinkCdkSession": {"type": "apiKey", "in": "header", "name": "X-Link-CDK-Session", "description": "由 POST /api/link-cdk/session 返回"},
      "AdminBearer": {"type": "http", "scheme": "bearer", "bearerFormat": "opaque"},
      "AdminTokenHeader": {"type": "apiKey", "in": "header", "name": "X-Link-CDK-Admin-Token"}
    },
    "parameters": {
      "BatchId": {"name": "batch_id", "in": "path", "required": true, "schema": {"type": "string"}},
      "CdkId": {"name": "cdk_id", "in": "path", "required": true, "schema": {"type": "string"}},
      "JobIdQuery": {"name": "job_id", "in": "query", "required": true, "schema": {"type": "string"}}
    },
    "responses": {
      "Ok": {"description": "操作完成", "content": {"application/json": {"schema": {"type": "object", "required": ["ok"], "properties": {"ok": {"type": "boolean"}}, "additionalProperties": true}}}},
      "BadRequest": {"description": "请求参数错误", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Unauthorized": {"description": "会话缺失或失效", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Forbidden": {"description": "CDK 不可用或资源不属于当前租户", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "NotFound": {"description": "资源不存在", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "Conflict": {"description": "资源占用或状态冲突", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "TooManyRequests": {"description": "请求频率受限", "headers": {"Retry-After": {"schema": {"type": "integer"}}}, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}},
      "BadGateway": {"description": "支付平台网络或响应错误", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorEnvelope"}}}}
    },
    "schemas": {
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean", "const": false},
          "error": {
            "oneOf": [
              {"type": "string"},
              {"type": "object", "required": ["code", "message"], "properties": {"code": {"type": "string"}, "message": {"type": "string"}}}
            ]
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "required": ["ok", "service", "link_type", "global_concurrency_limit", "active_jobs", "queued_jobs", "running_jobs", "payment_success_jobs"],
        "properties": {
          "ok": {"type": "boolean"},
          "service": {"type": "string"},
          "link_type": {"type": "string"},
          "global_concurrency_limit": {"type": "integer"},
          "active_jobs": {"type": "integer"},
          "queued_jobs": {"type": "integer"},
          "running_jobs": {"type": "integer"},
          "payment_success_jobs": {"type": "integer"}
        }
      },
      "LinkCdkCodeRequest": {
        "type": "object",
        "required": ["code"],
        "properties": {"code": {"type": "string", "examples": ["UPI-CDK-598D-9C61-541B"]}}
      },
      "LinkCdkStatus": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "code_masked": {"type": "string"},
          "status": {"type": "string", "enum": ["active", "disabled", "deleted", "merged", "exhausted"]},
          "remaining_uses": {"type": "integer"},
          "reserved_uses": {"type": "integer"},
          "available_uses": {"type": "integer"},
          "concurrency_limit": {"type": "integer"},
          "fusion_allowed": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "LinkCdkStatusResponse": {
        "allOf": [
          {"type": "object", "properties": {"ok": {"type": "boolean"}}},
          {"$ref": "#/components/schemas/LinkCdkStatus"}
        ]
      },
      "LinkCdkSessionResponse": {
        "type": "object",
        "required": ["ok", "token", "expires_at", "link_cdk"],
        "properties": {
          "ok": {"type": "boolean"},
          "token": {"type": "string"},
          "expires_at": {"type": "number"},
          "link_cdk": {"$ref": "#/components/schemas/LinkCdkStatus"}
        }
      },
      "PaymentProviderId": {"type": "string", "enum": ["foarge", "xxsyun", "astrascan"], "default": "foarge"},
      "PaymentProviderRequest": {
        "type": "object",
        "required": ["provider_id"],
        "properties": {"provider_id": {"$ref": "#/components/schemas/PaymentProviderId"}}
      },
      "PaymentProviderStatus": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean"},
          "provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "label": {"type": "string"},
          "submit_interval_seconds": {"type": "number"},
          "configured": {"type": "boolean"},
          "enabled": {"type": "boolean"},
          "quota_remaining": {"type": ["integer", "null"]},
          "quota_known": {"type": "boolean"},
          "quota_updated_at": {"type": "number"},
          "quota_blocked": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "PaymentStatusResponse": {
        "type": "object",
        "properties": {
          "ok": {"type": "boolean"},
          "selected_provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "enabled": {"type": "boolean"},
          "providers": {"type": "array", "items": {"$ref": "#/components/schemas/PaymentProviderStatus"}}
        }
      },
      "BatchCreateRequest": {
        "type": "object",
        "required": ["tokens", "entry_proxies", "link_cdk"],
        "properties": {
          "tokens": {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string"}},
          "entry_proxies": {"type": "array", "minItems": 1, "maxItems": 5000, "items": {"type": "string"}},
          "link_cdk": {"type": "string"},
          "payment_provider_id": {"$ref": "#/components/schemas/PaymentProviderId"},
          "use_promo": {"type": "boolean", "default": true},
          "promo_campaign": {"type": "string", "default": "plus-1-month-free"}
        }
      },
      "BatchCreateResponse": {
        "type": "object",
        "required": ["ok", "batch_id", "batch_size", "jobs"],
        "properties": {
          "ok": {"type": "boolean"},
          "batch_id": {"type": "string"},
          "batch_size": {"type": "integer"},
          "jobs": {"type": "array", "items": {"type": "object", "properties": {"index": {"type": "integer"}, "account_email": {"type": "string"}, "job_id": {"type": "string"}, "queue_position": {"type": "integer"}}}},
          "workers": {"type": "integer"},
          "batch_workers": {"type": "integer"},
          "payment_provider_id": {"type": "string"},
          "payment_auto_submit": {"type": "boolean"}
        },
        "additionalProperties": true
      },
      "JobPayment": {
        "type": "object",
        "properties": {
          "provider_id": {"type": "string"},
          "status": {"type": "string", "enum": ["not_submitted", "awaiting_worker", "queued", "submission_waiting", "submitting", "submit_failed", "tracking_retrying", "tracking_failed", "quota_insufficient", "completed", "failed", "expired", "cancelled"]},
          "order_id": {"type": "string"},
          "order_status": {"type": "string"},
          "text": {"type": "string"},
          "code": {"type": "string"},
          "error": {"type": "string"},
          "attempts": {"type": "integer"},
          "updated_at": {"type": "number"}
        },
        "additionalProperties": true
      },
      "Job": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "batch_id": {"type": "string"},
          "batch_index": {"type": "integer"},
          "batch_size": {"type": "integer"},
          "account_email": {"type": "string"},
          "status": {"type": "string", "enum": ["queued", "running", "done", "error", "cancelled"]},
          "percent": {"type": "integer", "minimum": 0, "maximum": 100},
          "text": {"type": "string"},
          "queue_position": {"type": "integer"},
          "error": {"type": "string"},
          "result": {"type": ["object", "null"], "additionalProperties": true},
          "payment": {"$ref": "#/components/schemas/JobPayment"},
          "created_at": {"type": "number"},
          "updated_at": {"type": "number"}
        },
        "additionalProperties": true
      },
      "BatchSnapshot": {
        "type": "object",
        "required": ["batch_id", "batch_size", "running", "completed", "succeeded", "failed", "cancelled", "jobs"],
        "properties": {
          "batch_id": {"type": "string"},
          "batch_size": {"type": "integer"},
          "running": {"type": "boolean"},
          "completed": {"type": "integer"},
          "succeeded": {"type": "integer"},
          "failed": {"type": "integer"},
          "cancelled": {"type": "integer"},
          "jobs": {"type": "array", "items": {"$ref": "#/components/schemas/Job"}},
          "logs": {"type": "array", "items": {"type": "object", "additionalProperties": true}}
        }
      },
      "JobIdRequest": {
        "type": "object",
        "required": ["job_id"],
        "properties": {"job_id": {"type": "string"}}
      },
      "GenerateLinkCdksRequest": {
        "type": "object",
        "required": ["count", "uses"],
        "properties": {
          "count": {"type": "integer", "minimum": 1},
          "uses": {"type": "integer", "enum": [10, 30, 50, 100, 200, 500, 1000]},
          "concurrency_limit": {"type": "integer", "enum": [10, 20, 30, 50, 100], "default": 10},
          "fusion_type": {"type": "string", "enum": ["mergeable", "non_mergeable"], "default": "mergeable"},
          "label": {"type": "string"}
        }
      }
    }
  }
}
