{
  "openapi": "3.1.0",
  "info": {
    "title": "UPI Paid API",
    "version": "1.0.0",
    "description": "Paid UPI extraction and worker scan-order APIs for upi.newzoe.cloud."
  },
  "servers": [{"url": "https://upi.newzoe.cloud"}],
  "paths": {
    "/api/v1/paid/extract": {
      "post": {
        "summary": "Extract a paid UPI instructions URL",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaidExtractRequest"}}}},
        "responses": {"200": {"description": "Extraction result", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PaidExtractResponse"}}}}, "default": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/api/v1/paid/scan-orders": {
      "post": {
        "summary": "Create a worker scan order",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScanOrderRequest"}}}},
        "responses": {"201": {"description": "Order created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScanOrderResponse"}}}}, "default": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/api/v1/paid/scan-orders/{order_id}": {
      "get": {
        "summary": "Get scan-order status",
        "parameters": [{"name": "order_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "status_token", "in": "query", "required": true, "schema": {"type": "string"}}],
        "responses": {"200": {"description": "Order status", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ScanStatusResponse"}}}}, "default": {"$ref": "#/components/responses/Error"}}
      }
    }
  },
  "components": {
    "schemas": {
      "PaidExtractRequest": {"type": "object", "required": ["access_token", "cdk"], "properties": {"access_token": {"type": "string"}, "cdk": {"type": "string"}, "country": {"type": "string", "default": "IN"}, "telegram_session_id": {"type": "string"}}},
      "PaidExtractResponse": {"type": "object", "properties": {"ok": {"type": "boolean"}, "request_id": {"type": "string"}, "data": {"type": "object", "properties": {"upi_url": {"type": "string"}, "payment_monitor_id": {"type": "string"}, "cdk_remaining_uses": {"type": "integer"}, "cdk_total_uses": {"type": "integer"}}}}},
      "ScanOrderRequest": {"type": "object", "required": ["upi_url", "gold_cdk"], "properties": {"upi_url": {"type": "string", "format": "uri"}, "gold_cdk": {"type": "string"}, "telegram_session_id": {"type": "string"}}},
      "ScanOrderResponse": {"type": "object", "properties": {"ok": {"type": "boolean"}, "data": {"$ref": "#/components/schemas/ScanOrder"}}},
      "ScanStatusResponse": {"type": "object", "properties": {"ok": {"type": "boolean"}, "data": {"$ref": "#/components/schemas/ScanStatus"}}},
      "ScanOrder": {"type": "object", "properties": {"order_id": {"type": "string"}, "status": {"type": "string", "enum": ["available", "claimed", "paid", "unpaid", "expired", "failed"]}, "expires_at": {"type": "integer"}, "upi_url": {"type": "string"}, "status_token": {"type": "string"}, "cdk_remaining_uses": {"type": "integer"}, "cdk_total_uses": {"type": "integer"}}},
      "ScanStatus": {"type": "object", "properties": {"order_id": {"type": "string"}, "status": {"type": "string"}, "gold_point_state": {"type": "string"}, "cdk_remaining_uses": {"type": ["integer", "null"]}, "cdk_total_uses": {"type": ["integer", "null"]}, "can_complain": {"type": "boolean"}, "complaint_submitted": {"type": "boolean"}}},
      "Error": {"type": "object", "properties": {"ok": {"type": "boolean", "const": false}, "code": {"type": "string"}, "message": {"type": "string"}}}
    },
    "responses": {"Error": {"description": "API error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}
  }
}
