{
  "openapi": "3.1.0",
  "info": {
    "title": "Dory Shop Customer API",
    "version": "1.1.0",
    "description": "Серверный API магазина Dory Proxy: каталог прокси, VPN и Telegram Premium; расчёт и создание заказов с баланса аккаунта. API-ключ передаётся только в Authorization: Bearer. Все денежные значения — целые центы USD. Через API доступен только Premium на 1 месяц для заранее подключённого в Mini App Telegram-аккаунта."
  },
  "servers": [
    {
      "url": "https://dory-proxy.forum/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "Баланс и состояние покупок"
    },
    {
      "name": "Catalog",
      "description": "Товары и актуальные параметры выбора"
    },
    {
      "name": "Orders",
      "description": "Расчёт, создание и получение заказов"
    },
    {
      "name": "Usage",
      "description": "Показания трафика по выданному заказу"
    },
    {
      "name": "VPN",
      "description": "Тарифы, покупка и получение ссылки HAPP"
    },
    {
      "name": "Premium",
      "description": "Покупка Premium на 1 месяц для подключённого Telegram-аккаунта"
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getAccount",
        "summary": "Получить аккаунт и доступность покупок",
        "responses": {
          "200": {
            "description": "Состояние аккаунта",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getBalance",
        "summary": "Получить баланс",
        "responses": {
          "200": {
            "description": "Баланс аккаунта",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BalanceResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/catalog": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "operationId": "listProducts",
        "summary": "Получить каталог товаров",
        "description": "Товар подходит для заказа, когда available и configurable равны true. display_price — опубликованная цена для ориентира; перед покупкой запрашивай серверную котировку.",
        "responses": {
          "200": {
            "description": "Актуальный каталог",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/catalog/{product_id}/options": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "operationId": "getProductOptions",
        "summary": "Получить параметры товара",
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "description": "id из GET /catalog",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Актуальные страны, сроки и допустимые настройки",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductOptions"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ApiError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/quotes": {
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "createQuote",
        "summary": "Рассчитать итоговую цену",
        "description": "Проверяет текущие параметры товара и рассчитывает цену на сервере. Котировка действует 10 минут. Лимит: 30 запросов в минуту на аккаунт.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Сумма, скидка, баланс и срок действия котировки",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ApiError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/orders": {
      "get": {
        "tags": [
          "Orders"
        ],
        "operationId": "listOrders",
        "summary": "Получить заказы этого API-ключа",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10000,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Страница заказов, созданных этим ключом",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderListResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "Orders"
        ],
        "operationId": "createOrder",
        "summary": "Оформить покупку по котировке",
        "description": "Списывает итоговую сумму с общего баланса аккаунта. Лимит: 15 запросов в минуту на аккаунт. При повторе той же операции передай прежний Idempotency-Key.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Уникальный ключ одной покупки; для безопасного повтора используй то же значение.",
            "schema": {
              "type": "string",
              "minLength": 16,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9._~-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateOrderRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Текущее состояние уже обработанного заказа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateOrderResponse"
                }
              }
            }
          },
          "202": {
            "description": "Заказ принят и обрабатывается",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateOrderResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/ApiError"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/ApiError"
          },
          "422": {
            "$ref": "#/components/responses/ApiError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}": {
      "get": {
        "tags": [
          "Orders"
        ],
        "operationId": "getOrder",
        "summary": "Получить статус и выданные прокси",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Заказ; строки прокси заполняются только после успешной выдачи",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderDetail"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/orders/{order_id}/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "operationId": "getOrderUsage",
        "summary": "Получить расход и остаток трафика",
        "description": "Лимит: 12 запросов в минуту на API-ключ. Для планов без счётчика поставщика вернётся state=not_metered; неизвестное значение не заменяется нулём.",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Состояние показаний и, если доступны, значения расхода",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/vpn": {
      "get": {
        "tags": [
          "VPN"
        ],
        "operationId": "getVpnCatalog",
        "summary": "Получить тарифы VPN",
        "responses": {
          "200": {
            "description": "Доступные сроки и цены VPN",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/vpn/quotes": {
      "post": {
        "tags": [
          "VPN"
        ],
        "operationId": "createVpnQuote",
        "summary": "Рассчитать цену VPN",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "days"
                ],
                "properties": {
                  "days": {
                    "type": "integer",
                    "enum": [
                      7,
                      14,
                      30,
                      90,
                      180,
                      360
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Котировка VPN и баланс аккаунта",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/vpn/orders": {
      "get": {
        "tags": [
          "VPN"
        ],
        "operationId": "listVpnOrders",
        "summary": "Список заказов VPN",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Заказы VPN этого API-ключа",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "VPN"
        ],
        "operationId": "createVpnOrder",
        "summary": "Купить VPN",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 16,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "quote_id"
                ],
                "properties": {
                  "quote_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Заказ VPN; ссылка HAPP доступна после завершения",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/vpn/orders/{order_id}": {
      "get": {
        "tags": [
          "VPN"
        ],
        "operationId": "getVpnOrder",
        "summary": "Статус и ссылка HAPP",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Статус, срок действия и ссылка HAPP",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/premium": {
      "get": {
        "tags": [
          "Premium"
        ],
        "operationId": "getPremiumCatalog",
        "summary": "Получить тариф Premium на 1 месяц",
        "responses": {
          "200": {
            "description": "Тариф Premium на 1 месяц",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "description": "Для оформления заранее подключи Telegram-аккаунт в Mini App."
      }
    },
    "/premium/quotes": {
      "post": {
        "tags": [
          "Premium"
        ],
        "operationId": "createPremiumQuote",
        "summary": "Рассчитать Premium на 1 месяц",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "months": {
                    "const": 1,
                    "type": "integer",
                    "description": "Допускается только 1 месяц."
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Котировка Premium и баланс аккаунта",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "description": "Для оформления заранее подключи Telegram-аккаунт в Mini App."
      }
    },
    "/premium/orders": {
      "get": {
        "tags": [
          "Premium"
        ],
        "operationId": "listPremiumOrders",
        "summary": "Список заказов Premium на месяц",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Заказы Premium этого API-ключа",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "description": "Для оформления заранее подключи Telegram-аккаунт в Mini App."
      },
      "post": {
        "tags": [
          "Premium"
        ],
        "operationId": "createPremiumOrder",
        "summary": "Купить Premium на 1 месяц",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 16,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "quote_id"
                ],
                "properties": {
                  "quote_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Состояние покупки Premium",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "description": "Для оформления заранее подключи Telegram-аккаунт в Mini App."
      }
    },
    "/premium/orders/{order_id}": {
      "get": {
        "tags": [
          "Premium"
        ],
        "operationId": "getPremiumOrder",
        "summary": "Статус заказа Premium на месяц",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Статус, срок и получатель подписки",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ApiError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "description": "Для оформления заранее подключи Telegram-аккаунт в Mini App."
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Dory Proxy API key",
        "description": "Передавай секретный ключ только в Authorization. Не помещай его в URL или код браузера."
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "MeResponse": {
        "type": "object",
        "required": [
          "account_id",
          "currency",
          "balance_cents",
          "purchases_enabled"
        ],
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "currency": {
            "const": "USD"
          },
          "balance_cents": {
            "type": "integer",
            "minimum": 0
          },
          "purchases_enabled": {
            "type": "boolean"
          }
        }
      },
      "BalanceResponse": {
        "type": "object",
        "required": [
          "currency",
          "balance_cents"
        ],
        "properties": {
          "currency": {
            "const": "USD"
          },
          "balance_cents": {
            "type": "integer",
            "minimum": 0,
            "description": "Целое число центов USD."
          }
        }
      },
      "DisplayPrice": {
        "type": [
          "object",
          "null"
        ],
        "required": [
          "amount_cents",
          "quantity",
          "unit"
        ],
        "properties": {
          "amount_cents": {
            "type": "integer"
          },
          "quantity": {
            "type": "integer"
          },
          "unit": {
            "type": "string"
          },
          "period": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CatalogProduct": {
        "type": "object",
        "required": [
          "id",
          "name",
          "family",
          "shape",
          "unit",
          "minimum",
          "maximum",
          "allowed",
          "available",
          "configurable",
          "display_price",
          "connection",
          "capabilities",
          "features"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "family": {
            "type": "string",
            "description": "Категория поставщика, например Residential, IPv4, IPv6, ISP или Mobile."
          },
          "shape": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "minimum": {
            "type": "integer"
          },
          "maximum": {
            "type": "integer"
          },
          "allowed": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "available": {
            "type": "boolean"
          },
          "configurable": {
            "type": "boolean"
          },
          "display_price": {
            "$ref": "#/components/schemas/DisplayPrice"
          },
          "connection": {
            "type": "object",
            "additionalProperties": true
          },
          "capabilities": {
            "type": "object",
            "additionalProperties": true
          },
          "features": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "CatalogResponse": {
        "type": "object",
        "required": [
          "currency",
          "products"
        ],
        "properties": {
          "currency": {
            "const": "USD"
          },
          "products": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CatalogProduct"
            }
          }
        }
      },
      "CountryOption": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "operators": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "PeriodOption": {
        "type": "object",
        "required": [
          "days",
          "label"
        ],
        "properties": {
          "days": {
            "type": "integer",
            "minimum": 1
          },
          "label": {
            "type": "string"
          }
        }
      },
      "ProductOptions": {
        "type": "object",
        "required": [
          "countries",
          "periods",
          "country_required",
          "mobile",
          "connection_controls"
        ],
        "properties": {
          "countries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CountryOption"
            }
          },
          "periods": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PeriodOption"
            }
          },
          "country_required": {
            "type": "boolean"
          },
          "mobile": {
            "type": "boolean"
          },
          "connection_controls": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        }
      },
      "Selection": {
        "type": "object",
        "required": [
          "quantity"
        ],
        "description": "Форма зависит от shape товара. Используй только поля и значения, которые возвращает options.",
        "properties": {
          "quantity": {
            "type": "integer",
            "minimum": 1
          },
          "country": {
            "type": "string"
          },
          "period_days": {
            "type": "integer",
            "minimum": 1
          },
          "service_type": {
            "type": "string",
            "enum": [
              "dedicated",
              "shared"
            ]
          },
          "operator_id": {
            "type": "string"
          },
          "rotation_id": {
            "type": "string"
          },
          "connection": {
            "type": "object",
            "description": "Настройки подключения только из connection_controls товара.",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "QuoteRequest": {
        "type": "object",
        "required": [
          "product_id",
          "selection"
        ],
        "properties": {
          "product_id": {
            "type": "string"
          },
          "selection": {
            "$ref": "#/components/schemas/Selection"
          },
          "promo_code": {
            "type": "string"
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "required": [
          "quote_id",
          "currency",
          "base_cents",
          "discount_cents",
          "total_cents",
          "balance_cents",
          "promo_code",
          "expires_at",
          "purchases_enabled"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{24}$"
          },
          "currency": {
            "const": "USD"
          },
          "base_cents": {
            "type": "integer"
          },
          "discount_cents": {
            "type": "integer"
          },
          "total_cents": {
            "type": "integer"
          },
          "balance_cents": {
            "type": "integer"
          },
          "promo_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix time in seconds."
          },
          "purchases_enabled": {
            "type": "boolean"
          }
        }
      },
      "CreateOrderRequest": {
        "type": "object",
        "required": [
          "quote_id"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "pattern": "^[a-f0-9]{24}$"
          }
        }
      },
      "CreateOrderResponse": {
        "type": "object",
        "required": [
          "order_id",
          "status",
          "stage",
          "charged_from_balance"
        ],
        "properties": {
          "order_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "stage": {
            "type": "string"
          },
          "charged_from_balance": {
            "const": true
          }
        }
      },
      "OrderSummary": {
        "type": "object",
        "required": [
          "order_id",
          "product_id",
          "product",
          "status",
          "stage",
          "quantity",
          "unit",
          "country",
          "amount_cents",
          "currency",
          "created_at"
        ],
        "properties": {
          "order_id": {
            "type": "string"
          },
          "product_id": {
            "type": "string"
          },
          "product": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "stage": {
            "type": "string"
          },
          "quantity": {
            "type": [
              "integer",
              "null"
            ]
          },
          "unit": {
            "type": "string"
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "amount_cents": {
            "type": "integer"
          },
          "currency": {
            "const": "USD"
          },
          "created_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix time in seconds."
          }
        }
      },
      "OrderListResponse": {
        "type": "object",
        "required": [
          "orders",
          "page",
          "limit",
          "has_more"
        ],
        "properties": {
          "orders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderSummary"
            }
          },
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "OrderDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/OrderSummary"
          },
          {
            "type": "object",
            "required": [
              "protocol",
              "format",
              "proxies"
            ],
            "properties": {
              "protocol": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "format": {
                "const": "host:port:login:password"
              },
              "proxies": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Пусто, пока выдача не завершена."
              }
            }
          }
        ]
      },
      "UsageDay": {
        "type": "object",
        "required": [
          "day",
          "used_gb"
        ],
        "properties": {
          "day": {
            "type": "string",
            "format": "date"
          },
          "used_gb": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      },
      "UsageResponse": {
        "type": "object",
        "required": [
          "state"
        ],
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "pending",
              "available",
              "not_metered",
              "unavailable",
              "inactive"
            ]
          },
          "total_gb": {
            "type": [
              "number",
              "null"
            ]
          },
          "remaining_gb": {
            "type": [
              "number",
              "null"
            ]
          },
          "used_gb": {
            "type": [
              "number",
              "null"
            ]
          },
          "usage_as_of": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "checked_at": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "expires_at": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "daily": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageDay"
            }
          },
          "unknown_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "stale": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "ApiError": {
        "description": "Структурированная ошибка API",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Ключ отсутствует, неверен или отозван",
        "headers": {
          "WWW-Authenticate": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Forbidden": {
        "description": "У API-ключа недостаточно прав",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "NotFound": {
        "description": "Товар или заказ не найден для данного API-ключа",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Лимит запросов; повтори запрос после указанной паузы",
        "headers": {
          "Retry-After": {
            "description": "Секунд до следующей попытки",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "InternalError": {
        "description": "Внутренняя ошибка сервиса",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Покупки временно недоступны",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            }
          }
        }
      }
    }
  }
}
