openapi: 3.0.3
info:
  title: Botads Client API
  version: 1.0.0
  description: >
    Публичный Client API для выдачи одноразовых short code по bot_id и user_tg_id.

servers:
  - url: https://api.botads.app

paths:
  /client/v1/codes:
    post:
      summary: Create short code
      description: Возвращает одноразовый short code для direct link сценариев.
      tags: [client]
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCodeRequest'
            example:
              bot_id: "123456789"
              user_tg_id: "799001234"
      responses:
        '200':
          description: Short code created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCodeResponse'
              example:
                code: AbCxxxxxx
                expires_in: 3600
                expires_at: 2024-05-26T12:00:00Z
        '400':
          description: INVALID_ARGUMENT
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: INVALID_ARGUMENT
                  message: invalid parameters
        '401':
          description: UNAUTHORIZED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: UNAUTHORIZED
                  message: unauthorized
        '403':
          description: FORBIDDEN
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: FORBIDDEN
                  message: forbidden
        '404':
          description: BOT_NOT_FOUND
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: BOT_NOT_FOUND
                  message: bot not found
        '500':
          description: INTERNAL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: INTERNAL
                  message: internal error

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

  schemas:
    CreateCodeRequest:
      type: object
      required: [bot_id, user_tg_id]
      properties:
        bot_id:
          type: string
          description: Bot id
        user_tg_id:
          type: string
          description: Telegram user id (строка с цифрами)
          pattern: '^\d{1,20}$'

    CreateCodeResponse:
      type: object
      required: [code, expires_in, expires_at]
      properties:
        code:
          type: string
          description: Short code (префикс бота + случайный суффикс)
        expires_in:
          type: integer
          format: int64
          description: TTL в секундах (default 3600)
          default: 3600
        expires_at:
          type: string
          format: date-time
          description: ISO8601 timestamp истечения

    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
            message:
              type: string
            details:
              type: object
