{
  "openapi": "3.1.0",
  "info": {
    "title": "GateProxy API",
    "version": "1.0",
    "description": "Order GateProxy proxies, sub-users and CD keys with your bot balance. Docs: https://docs.gateproxy.store"
  },
  "servers": [{ "url": "https://api.gateproxy.store/v1" }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "API key generated in the bot (gpk_live_...)" }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "request_id"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "request_id": { "type": "string" }
            }
          }
        }
      },
      "Plan": {
        "type": "object",
        "properties": {
          "plan": { "type": "string", "example": "1" },
          "label": { "type": "string", "example": "1 GB" },
          "price_usd": { "type": "number", "example": 1.1 },
          "in_stock": { "type": "boolean" },
          "stock": { "type": "integer", "description": "CD-key products only" }
        }
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "dataimpulse" },
          "name": { "type": "string" },
          "type": { "type": "string", "enum": ["subuser", "cdkey"] },
          "refundable": { "type": "boolean" },
          "plans": { "type": "array", "items": { "$ref": "#/components/schemas/Plan" } }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "ord_5c1f0b9a2e7d43a1b6c8d901" },
          "status": { "type": "string", "enum": ["processing", "completed", "failed", "review", "refunded"] },
          "product": { "type": "string" },
          "plan": { "type": "string" },
          "plan_label": { "type": "string" },
          "price_usd": { "type": "number" },
          "charged": { "type": "boolean" },
          "created_at": { "type": "string", "format": "date-time" },
          "completed_at": { "type": ["string", "null"], "format": "date-time" },
          "delivery": { "type": "object", "description": "Present when status is completed" },
          "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" } } }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": { "summary": "Health check", "security": [], "responses": { "200": { "description": "OK" } } }
    },
    "/me": {
      "get": { "summary": "Account, balance, limits", "responses": { "200": { "description": "Account" }, "401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } } }
    },
    "/balance": {
      "get": { "summary": "Balance in USD", "responses": { "200": { "description": "Balance" } } }
    },
    "/products": {
      "get": {
        "summary": "Products on sale with your prices",
        "responses": { "200": { "description": "Products", "content": { "application/json": { "schema": { "type": "object", "properties": { "products": { "type": "array", "items": { "$ref": "#/components/schemas/Product" } } } } } } } }
      }
    },
    "/products/{product_id}": {
      "get": {
        "summary": "One product",
        "parameters": [{ "name": "product_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Product" }, "404": { "description": "Unknown product" } }
      }
    },
    "/orders": {
      "post": {
        "summary": "Create an order (waits for delivery, up to ~90 s)",
        "parameters": [{ "name": "Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string", "minLength": 8, "maxLength": 64 } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["product", "plan"], "properties": { "product": { "type": "string", "example": "dataimpulse" }, "plan": { "type": "string", "example": "1" } } } } }
        },
        "responses": {
          "201": { "description": "Delivered", "content": { "application/json": { "schema": { "type": "object", "properties": { "order": { "$ref": "#/components/schemas/Order" } } } } } },
          "202": { "description": "Still processing or under review — poll GET /orders/{id}" },
          "402": { "description": "Insufficient balance (nothing charged)" },
          "409": { "description": "Out of stock / unavailable / idempotency conflict" },
          "429": { "description": "Rate limited" },
          "502": { "description": "Provider rejected the order (refunded)" }
        }
      },
      "get": {
        "summary": "List your orders",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100 } },
          { "name": "status", "in": "query", "schema": { "type": "string" } },
          { "name": "before", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Orders" } }
      }
    },
    "/orders/{order_id}": {
      "get": {
        "summary": "Get one order",
        "parameters": [{ "name": "order_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Order" }, "404": { "description": "Not found" } }
      }
    }
  }
}
