openapi: '3.0.0'
info:
  title: Messenger Service
  contact:
    name: Tradesoft
    url: 'https://www.tradesoft.ru/about/contacts/'
    email: service@tradesoft.ru
  version: 1.1.0

servers:
  - url: https://messenger.app.tradesoft.ru/
    description: Messenger server

paths:
  /provider/:
    get:
      deprecated: true
      operationId: getProvider
      tags:
        - Messenger
      summary: Получить список поставщиков
      description: >-
        Получить список поставщиков
      parameters:
        - $ref: '#/components/parameters/Accept-Language'
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/providerResponse'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
  /provider2/:
    get:
      operationId: getProvider2
      tags:
        - Messenger
      summary: Получить список поставщиков
      description: >-
        Получить список поставщиков
      parameters:
        - $ref: '#/components/parameters/Accept-Language'
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    description: Список поставщиков
                    type: array
                    items:
                      $ref: '#/components/schemas/providerResponse'
                  geoDictionary:
                    description: Список данных по гео меткам, которые присутствуют в выборке
                    type: array
                    items:
                      $ref: '#/components/schemas/geoDictionary'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
  /credential/:
    get:
      operationId: getCredentialList
      tags:
        - Messenger
      summary: Получить список реквизитов
      description: >-
        Получить список реквизитов
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/getCredentialModel'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
    post:
      operationId: postCredential
      tags:
        - Messenger
      summary: Добавить рекизиты доступа
      description: >-
        Добавить рекизиты доступа
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/postCredentialModel'
      responses:
        200:
          description: Successful operation
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
  /credential/{id}:
    get:
      operationId: getCredential
      tags:
        - Messenger
      summary: Получить реквизит по id
      description: >-
        Получить реквизит по id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: '5c9ccee739a6d016305f9695'
          description: Идентификатор реквизита доступа
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/getCredentialModel'
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
        404:
          $ref: '#/components/responses/404NotFound'
    put:
      operationId: putCredential
      tags:
        - Messenger
      summary: Обновить данные рекизитов доступа
      description: >-
        Обновить данные рекизитов доступа
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: '5c9ccee739a6d016305f9695'
          description: Идентификатор реквизита доступа
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/putCredentialModel'
      responses:
        200:
          description: Successful operation
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
        404:
          $ref: '#/components/responses/404NotFound'
    delete:
      operationId: deleteCredential
      tags:
        - Messenger
      summary: Удалить данные рекизитов доступа
      description: >-
        Удалить данные рекизитов доступа
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: '5c9ccee739a6d016305f9695'
          description: Идентификатор реквизита доступа
      responses:
        200:
          description: Successful operation
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
        404:
          $ref: '#/components/responses/404NotFound'
  /message/:
    post:
      operationId: postMessage
      tags:
        - Messenger
      summary: Отправить список сообщений
      description: >-
        Отправить список сообщений<br/>
        Лимит на отправку - не более <strong>500 сообщений</strong> в одном пакете
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/postMessageRequest'
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/postMessageResponse'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
  /message/{id}:
    get:
      operationId: getMessage
      tags:
        - Messenger
      summary: Получить информацию по сообщению
      description: >-
        Получить информацию по сообщению
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: '5c9ccee739a6d016305f9695'
          description: Идентификатор сообщения
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/getMessageResponse'
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
        404:
          $ref: '#/components/responses/404NotFound'
  /status/:
    get:
      operationId: status
      tags:
        - Messenger
      summary: Получить информацию по сообщениям
      description: >-
        Получить информацию по сообщениям.<br/><strong>Не больше 500 сообщений за раз</strong>
      parameters:
        - name: ids
          in: query
          required: true
          schema:
            type: string
            example: '5c9ccee739a6d016305f9695,5c9ccee739a6d016305f9696,5c9ccee739a6d016305f9697'
          description: Идентификаторы сообщения, через запятую
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/getMessageResponse'
        400:
          $ref: '#/components/responses/400BadRequest'
        401:
          $ref: '#/components/responses/401Unauthorized'
        403:
          $ref: '#/components/responses/403AccessDeny'
        404:
          $ref: '#/components/responses/404NotFound'
        414:
          $ref: '#/components/responses/414QueryTooLong'

components:
  schemas:
    postMessageRequest:
      required: [provider, text, receiver]
      properties:
        text:
          type: string
          description: Текст сообщения
          example: 'Ваш заказ №123 отправлен.'
        receiver:
          type: string
          description: Получатель сообщения
          example: "79991234567"
        credentialId:
          type: string
          description: Идентификатор реквизита доступа
          example: '5c9ccee4c69fd750917780c3'
    providerResponse:
      properties:
        id:
          type: string
          description: Идентификатор поставщика
          example: enterix
        name:
          type: string
          description: Название поставщика
          example: Enterix
        siteUrl:
          type: string
          format: url
          description: Ссыллка на сайт поставщика
          example: http://enterix.ru/
        description:
          type: string
          description: Описание поставщика
          example: 'Описание'
        agreementText:
          type: string
          description: Условия подключения
          example: Нужно закалючить договоры с операторами связи самостоятельно
        geoIds:
          type: array
          description: Идентификаторы регионов, с которыми работает поставщик
          items:
            type: string
            example: 'eu.ru'
          example: ['eu', 'eu.ru']
        options:
          type: array
          description: Опции для редактирования/добавления реквизита доступа
          items:
            type: object
            properties:
              key:
                type: string
                description: Ключ поля
                example: 'sender_name'
              name:
                type: string
                description: Название поля
                example: 'Имя отправителя'
              type:
                type: string
                enum: ['string', 'password']
                description: Тип поля
              description:
                type: string
                description: Описание поля
                example: 'При отправке сообщения в поле "ОТ:" будет указано данное имя отправителя'
    putCredentialModel:
      properties:
        id:
          type: string
          description: Идентификатор реквизита
          example: '5c9ccee4c69fd750917780c3'
        name:
          type: string
          description: Название реквизита доступа
          example: 'Доступ к Enterix'
        providerId:
          type: string
          description: Идентификатор поставщика
          example: 'enterix'
        options:
          type: array
          description: Опции для реквизита доступа
          items:
            type: object
            properties:
              key:
                type: string
                description: Ключ поля
                example: 'sender_name'
              name:
                type: string
                description: Название поля
                example: 'Имя отправителя'
              type:
                type: string
                enum: ['string', 'password']
                description: Тип поля
              description:
                type: string
                description: Описание поля
                example: 'При отправке сообщения в поле "ОТ:" будет указано данное имя отправителя'
              value:
                type: string
                description: Значение поля
                example: 'TRADESOFT'
    getCredentialModel:
      properties:
        id:
          type: string
          description: Идентификатор реквизита
          example: '5c9ccee4c69fd750917780c3'
        name:
          type: string
          description: Название реквизита доступа
          example: 'Доступ к Enterix'
        providerId:
          type: string
          description: Идентификатор поставщика
          example: 'enterix'
        options:
          type: array
          description: Опции для реквизита доступа
          items:
            type: object
            properties:
              key:
                type: string
                description: Ключ поля
                example: 'sender_name'
              name:
                type: string
                description: Название поля
                example: 'Имя отправителя'
              type:
                type: string
                enum: ['string', 'password']
                description: Тип поля
              description:
                type: string
                description: Описание поля
                example: 'При отправке сообщения в поле "ОТ:" будет указано данное имя отправителя'
        optionsValue:
          type: array
          description: Значение опций
          items:
            type: object
            properties:
              key:
                type: string
                description: Ключ поля
                example: 'sender_name'
              value:
                type: string
                description: Значение поля
                example: 'TRADESOFT'
    postCredentialModel:
      properties:
        name:
          type: string
          description: Название реквизита доступа
          example: 'Доступ к Enterix'
        providerId:
          type: string
          description: Идентификатор поставщика
          example: 'enterix'
        optionsValue:
          type: array
          description: Значение опций
          items:
            type: object
            properties:
              key:
                type: string
                description: Ключ поля
                example: 'sender_name'
              value:
                type: string
                description: Значение поля
                example: 'TRADESOFT'
    postMessageResponse:
      properties:
        id:
          type: string
          description: Идентификатор отправи сообщения
          example: '5c9ccee739a6d016305f9695'
    getMessageResponse:
      properties:
        id:
          type: string
          description: Идентификатор отправи сообщения
          example: '5c9ccee739a6d016305f9695'
        credentialId:
          type: string
          description: Идентификатор реквизита, через который было отправлено сообщение
          example: '5c9ccee4c69fd750917780c3'
        statusCode:
          type: string
          description: Состояние отправки сообщения
          enum: ['created', 'error', 'in_progress', 'sended', 'send_checked', 'done']
          example: 'created'
        statusText:
          type: string
          description: Текст состояния
          example: 'Сообщение создано'
        final:
          type: boolean
          description: Выставлено финальное состояние и больше не меняется.
    geoDictionary:
      properties:
        key:
          description: Идентиикатор geoId
          type: string
          example: 'eu.ru'
        name:
          description: Название элемента
          type: string
          example: 'Россия'
        type:
          description: Тип идентификатора
          type: string
          enum: ['continent', 'country', 'subdivision1', 'subdivision2']
          example: 'country'
    ErrorResponse:
      properties:
        code:
          type: integer
          description: Код ошибки
        message:
          description: Текст ошибки
          type: string
  responses:
    400BadRequest:
      description: Bad Request
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/ErrorResponse'
              - example:
                  code: 400
                  message: bad request
    401Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/ErrorResponse'
              - example:
                  code: 401
                  message: Unauthorized
    403AccessDeny:
      description: Access deny
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/ErrorResponse'
              - example:
                  code: 403
                  message: Access deny
    404NotFound:
      description: Not found
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/ErrorResponse'
              - example:
                  code: 404
                  message: Not Found
    414QueryTooLong:
      description: Query too long
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/ErrorResponse'
              - example:
                  code: 414
                  message: Query too long
  securitySchemes:
    jwtToken:
      type: apiKey
      description: авторизация по API ключу
      name: Authorization
      in: header
  parameters:
    Accept-Language:
      in: header
      name: Accept-Language
      schema:
        type: string
security:
  - jwtToken: []
tags:
  - name: Messenger
    description: Сервис отправки сообщений