{
  "openapi": "3.1.1",
  "info": {
    "title": "EREZ Scope Partner API",
    "version": "1",
    "description": "Бои, сессии и изменения. Поля игроков зависят от прав ключа."
  },
  "servers": [
    {
      "url": "https://api.erezcore.com/api/v1"
    }
  ],
  "security": [
    {
      "PartnerKey": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "operationId": "getAccess",
        "summary": "Доступ ключа",
        "parameters": [],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Access"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/clans": {
      "get": {
        "operationId": "listClans",
        "summary": "Каталог полков",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/ClanAfter"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClanPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/battles": {
      "get": {
        "operationId": "listBattles",
        "summary": "Бои доступных полков",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanQuery"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BattlePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/clans/{clanId}/battles": {
      "get": {
        "operationId": "listClanBattles",
        "summary": "Бои полка",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanPath"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BattlePage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/clans/{clanId}/battles/{id}": {
      "get": {
        "operationId": "getBattle",
        "summary": "Детали боя",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanPath"
          },
          {
            "$ref": "#/components/parameters/ResourceId"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Battle"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/sessions": {
      "get": {
        "operationId": "listSessions",
        "summary": "Сессии доступных полков",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanQuery"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/clans/{clanId}/sessions": {
      "get": {
        "operationId": "listClanSessions",
        "summary": "Сессии полка",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanPath"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/clans/{clanId}/sessions/{id}": {
      "get": {
        "operationId": "getSession",
        "summary": "Детали сессии",
        "parameters": [
          {
            "$ref": "#/components/parameters/ClanPath"
          },
          {
            "$ref": "#/components/parameters/ResourceId"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "listUpdates",
        "summary": "Поток обновлений",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/EventAfter"
          },
          {
            "$ref": "#/components/parameters/ClanIds"
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-ответ.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error400"
          },
          "401": {
            "$ref": "#/components/responses/Error401"
          },
          "404": {
            "$ref": "#/components/responses/Error404"
          },
          "409": {
            "$ref": "#/components/responses/Error409"
          },
          "410": {
            "$ref": "#/components/responses/Error410"
          },
          "429": {
            "$ref": "#/components/responses/Error429"
          },
          "503": {
            "$ref": "#/components/responses/Error503"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "PartnerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Партнёрский ключ EREZ Scope."
      }
    },
    "parameters": {
      "ClanPath": {
        "name": "clanId",
        "in": "path",
        "required": true,
        "description": "ID полка.",
        "schema": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,19}$"
        }
      },
      "ClanQuery": {
        "name": "clanId",
        "in": "query",
        "required": false,
        "description": "Ограничить выдачу одним полком.",
        "schema": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,19}$"
        }
      },
      "ResourceId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "ID записи из списка.",
        "schema": {
          "type": "string",
          "pattern": "^[a-f0-9]{1,32}$"
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "required": false,
        "description": "Число записей на страницу.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 25,
          "default": 10
        }
      },
      "Before": {
        "name": "before",
        "in": "query",
        "required": false,
        "description": "nextCursor предыдущей страницы истории.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,400}$"
        }
      },
      "ClanAfter": {
        "name": "after",
        "in": "query",
        "required": false,
        "description": "ID последнего полка предыдущей страницы.",
        "schema": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,19}$"
        }
      },
      "EventAfter": {
        "name": "after",
        "in": "query",
        "required": false,
        "description": "Курсор потока. Без него возвращается текущая позиция.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,1000}$"
        }
      },
      "ClanIds": {
        "name": "clanIds",
        "in": "query",
        "required": false,
        "description": "До 20 уникальных ID через запятую. Используйте один фильтр на всех страницах.",
        "schema": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,19}(,[1-9][0-9]{0,19}){0,19}$"
        }
      }
    },
    "responses": {
      "Error400": {
        "description": "Неверные параметры.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error401": {
        "description": "Ключ отсутствует, неверен или отозван.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error404": {
        "description": "Ресурс отсутствует или недоступен.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error409": {
        "description": "Параметры доступа или курсора изменились.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error410": {
        "description": "Курсор устарел. Загрузите историю заново.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error429": {
        "description": "Лимит запросов.",
        "headers": {
          "Retry-After": {
            "description": "Интервал перед повтором в секундах.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Error503": {
        "description": "API временно недоступен.",
        "headers": {
          "Retry-After": {
            "description": "Интервал перед повтором в секундах.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Clan": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "tag": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "tag"
        ]
      },
      "ClanEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "tag": {
            "type": [
              "string",
              "null"
            ]
          },
          "dataAvailable": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "tag",
          "dataAvailable"
        ]
      },
      "Access": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "clanIds": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "permissions": {
            "type": "object",
            "properties": {
              "players": {
                "type": "boolean"
              },
              "opponentPlayers": {
                "type": "boolean"
              }
            },
            "required": [
              "players",
              "opponentPlayers"
            ]
          },
          "limits": {
            "type": "object",
            "properties": {
              "requestsPerMinute": {
                "type": "number"
              },
              "burst": {
                "type": "number"
              }
            },
            "required": [
              "requestsPerMinute",
              "burst"
            ]
          },
          "delaySeconds": {
            "type": "number"
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "syncCursor": {
            "type": "string"
          },
          "catalogue": {
            "type": "object",
            "properties": {
              "historyReady": {
                "type": "boolean"
              }
            },
            "required": [
              "historyReady"
            ]
          }
        },
        "required": [
          "name",
          "clanIds",
          "permissions",
          "limits",
          "delaySeconds",
          "expiresAt",
          "syncCursor",
          "catalogue"
        ]
      },
      "Statistics": {
        "type": "object",
        "properties": {
          "kills": {
            "type": [
              "number",
              "null"
            ]
          },
          "airKills": {
            "type": [
              "number",
              "null"
            ]
          },
          "groundKills": {
            "type": [
              "number",
              "null"
            ]
          },
          "navalKills": {
            "type": [
              "number",
              "null"
            ]
          },
          "deaths": {
            "type": [
              "number",
              "null"
            ]
          },
          "assists": {
            "type": [
              "number",
              "null"
            ]
          },
          "captures": {
            "type": [
              "number",
              "null"
            ]
          },
          "score": {
            "type": [
              "number",
              "null"
            ]
          }
        },
        "required": [
          "kills",
          "airKills",
          "groundKills",
          "navalKills",
          "deaths",
          "assists",
          "captures",
          "score"
        ]
      },
      "RatingDelta": {
        "type": "object",
        "properties": {
          "before": {
            "type": [
              "number",
              "null"
            ]
          },
          "after": {
            "type": [
              "number",
              "null"
            ]
          },
          "change": {
            "type": [
              "number",
              "null"
            ]
          }
        },
        "required": [
          "before",
          "after",
          "change"
        ]
      },
      "BattlePlayer": {
        "type": "object",
        "properties": {
          "uid": {
            "type": "string"
          },
          "nickname": {
            "type": "string"
          },
          "vehicle": {
            "type": [
              "string",
              "null"
            ]
          },
          "vehicleName": {
            "type": [
              "string",
              "null"
            ]
          },
          "rating": {
            "$ref": "#/components/schemas/RatingDelta"
          },
          "statistics": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Statistics"
              },
              {
                "type": "object",
                "properties": {
                  "complete": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "complete"
                ]
              }
            ]
          }
        },
        "required": [
          "uid",
          "nickname",
          "vehicle",
          "vehicleName",
          "rating",
          "statistics"
        ]
      },
      "Battle": {
        "type": "object",
        "properties": {
          "type": {
            "const": "battle"
          },
          "id": {
            "type": "string"
          },
          "clan": {
            "$ref": "#/components/schemas/Clan"
          },
          "sessionId": {
            "type": "string"
          },
          "startedAt": {
            "type": "string",
            "format": "date-time"
          },
          "endedAt": {
            "type": "string",
            "format": "date-time"
          },
          "durationSeconds": {
            "type": "number"
          },
          "map": {
            "type": [
              "string",
              "null"
            ]
          },
          "mode": {
            "type": [
              "string",
              "null"
            ]
          },
          "outcome": {
            "enum": [
              "win",
              "loss",
              "unknown"
            ]
          },
          "quality": {
            "enum": [
              "complete",
              "partial"
            ]
          },
          "rating": {
            "$ref": "#/components/schemas/RatingDelta"
          },
          "statistics": {
            "$ref": "#/components/schemas/Statistics"
          },
          "players": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BattlePlayer"
            }
          },
          "opponent": {
            "type": "object",
            "properties": {
              "tag": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "statistics": {
                "$ref": "#/components/schemas/Statistics"
              },
              "players": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/BattlePlayer"
                }
              }
            },
            "required": [
              "tag",
              "statistics"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "type",
          "id",
          "clan",
          "sessionId",
          "startedAt",
          "endedAt",
          "durationSeconds",
          "map",
          "mode",
          "outcome",
          "quality",
          "rating",
          "statistics",
          "opponent",
          "version",
          "updatedAt"
        ]
      },
      "SessionPlayer": {
        "type": "object",
        "properties": {
          "uid": {
            "type": "string"
          },
          "nickname": {
            "type": "string"
          },
          "rating": {
            "type": "object",
            "properties": {
              "value": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "change": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "value",
              "change"
            ]
          },
          "combat": {
            "type": "object",
            "properties": {
              "battles": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "observedBattles": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "verifiedBattles": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "kills": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "deaths": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "battles",
              "observedBattles",
              "verifiedBattles",
              "kills",
              "deaths"
            ]
          }
        },
        "required": [
          "uid",
          "nickname",
          "rating",
          "combat"
        ]
      },
      "Session": {
        "type": "object",
        "properties": {
          "type": {
            "const": "session"
          },
          "id": {
            "type": "string"
          },
          "clan": {
            "$ref": "#/components/schemas/Clan"
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "region": {
            "enum": [
              "EU",
              "NA"
            ]
          },
          "totals": {
            "type": "object",
            "properties": {
              "battles": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "wins": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "losses": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "unknown": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "winRate": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "battles",
              "wins",
              "losses",
              "unknown",
              "winRate"
            ]
          },
          "rating": {
            "type": "object",
            "properties": {
              "value": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "change": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "place": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "placeChange": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "value",
              "change",
              "place",
              "placeChange"
            ]
          },
          "quality": {
            "type": "object",
            "properties": {
              "state": {
                "enum": [
                  "preliminary",
                  "partial",
                  "final",
                  "unknown"
                ]
              },
              "knownBattles": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "pendingBattles": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "state",
              "knownBattles",
              "pendingBattles"
            ]
          },
          "players": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SessionPlayer"
            }
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "type",
          "id",
          "clan",
          "date",
          "region",
          "totals",
          "rating",
          "quality",
          "version",
          "updatedAt"
        ]
      },
      "Event": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "enum": [
              "battle.created",
              "battle.updated",
              "battle.deleted",
              "session.created",
              "session.updated",
              "session.deleted"
            ]
          },
          "clanId": {
            "type": "string"
          },
          "resourceId": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "publishedAt": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "description": "Снимок записи или отметка deleted: true."
          }
        },
        "required": [
          "id",
          "type",
          "clanId",
          "resourceId",
          "version",
          "publishedAt",
          "data"
        ]
      },
      "BattlePage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Battle"
            }
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "hasMore",
          "nextCursor"
        ]
      },
      "SessionPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Session"
            }
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "items",
          "hasMore",
          "nextCursor"
        ]
      },
      "ClanPage": {
        "type": "object",
        "properties": {
          "clans": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ClanEntry"
            }
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "clans",
          "hasMore",
          "nextCursor"
        ]
      },
      "EventPage": {
        "type": "object",
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            }
          },
          "hasMore": {
            "type": "boolean"
          },
          "nextCursor": {
            "type": "string"
          }
        },
        "required": [
          "events",
          "hasMore",
          "nextCursor"
        ]
      }
    }
  }
}
