openapi: "3.0.0"
info:
  version: 0.2.0
  title: Pararam API
  license:
    name: MIT
servers:
- url: https://api.pararam.io
paths:
  /core/user:
    get:
      summary: Get users info
      operationId: get_users
      security:
      - token: []
      parameters:
      - name: ids
        in: query
        required: true
        description: Comma separated user ids
        example: '11,12,15'
        schema:
          type: string
      responses:
        '200':
          description: Chat ids list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Users'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'
                
  /core/chat/sync:
    get:
      summary: Get my chats
      operationId: my_chats
      security:
      - token: []
      responses:
        '200':
          description: Chat ids list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatIds'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat:
    get:
      summary: Chats data
      operationId: fetch_chats
      security:
      - token: []
      parameters:
      - name: ids
        in: query
        required: true
        description: Comma separated chat ids
        example: '11,12,15'
        schema:
          type: string
      responses:
        '200':
          description: Chats list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Chats'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

    post:
      summary: Create new chat
      operationId: create_chat
      security:
      - token: []
      requestBody:
        description: Chat details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateChat'
      responses:
        '200':
          description: New chat response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'
  
  /core/chat/{chat_id}:
    put:
      summary: Update chat
      operationId: update_chat
      security:
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      requestBody:
        description: Chat details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateChat'
      responses:
        '200':
          description: Update chat response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

    delete:
      summary: Remove chat
      operationId: delete_chat
      security:
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Deleted chat response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/pm/{user_id}:
    post:
      summary: Get or create private chat
      operationId: private_chat
      security: 
      - token: []
      parameters: 
      - name: user_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Private chat response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/fork/{chat_id}:
    post:
      summary: Fork to new chat
      operationId: fork_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      requestBody:
        description: Fork details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Fork'
      responses:
        '200':
          description: Fork chat response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/favorite:
    post:
      summary: Make chat favorite
      operationId: favorite_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/unfavorite:
    post:
      summary: Remove chat from favorites
      operationId: unfavorite_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/hide:
    post:
      summary: Hide chat
      operationId: hide_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/show:
    post:
      summary: Show chat
      operationId: show_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/enter:
    post:
      summary: Enter to chat
      operationId: enter_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/chat/{chat_id}/quit:
    post:
      summary: Quit from chat
      operationId: quit_chat
      security: 
      - token: []
      parameters: 
      - name: chat_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Action response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'
                
  /core/org/sync:
    get:
      summary: Get my teams
      operationId: my_teams
      security:
      - token: []
      responses:
        '200':
          description: My team ids list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamIds'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/org:
    get:
      summary: Get teams data
      operationId: get_teams
      security:
      - token: []
      parameters:
      - name: ids
        in: query
        required: true
        description: Comma separated team ids
        example: '11,12,15'
        schema:
          type: string
      responses:
        '200':
          description: Team data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Teams'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

    post:
      summary: Create team
      operationId: create_team
      security:
      - token: []
      requestBody:
        description: Team details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TeamCreate'
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'
  
  /core/org/{team_id}:
    put:
      summary: Update team
      operationId: update_team
      security:
      - token: []
      parameters: 
      - name: team_id
        in: path
        required: true
        schema:
          type: integer
      requestBody:
        description: Chat details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TeamUpdate'
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

    delete:
      summary: Delete team
      operationId: delete_team
      security:
      - token: []
      parameters: 
      - name: team_id
        in: path
        required: true
        schema:
          type: integer
      - name: totp
        in: query
        required: true
        schema:
          type: string
      - name: code
        in: query
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/org/{team_id}/enter:
    post:
      summary: User enter to team
      operationId: enter_team
      security:
      - token: []
      parameters: 
      - name: team_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/org/{team_id}/quit:
    post:
      summary: User quit to team
      operationId: quit_team
      security:
      - token: []
      parameters: 
      - name: team_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

  /core/org/{team_id}/reject:
    post:
      summary: User reject to team
      operationId: reject_team
      security:
      - token: []
      parameters:
      - name: team_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Team id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamId'
        '400':
          description: Validation errors
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidatioError'
        '403':
          description: No access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NoAccess'

components:
  securitySchemes:
    token:
      type: apiKey
      in: header
      name: X-APIToken
  schemas:
    CreateChat:
      type: object
      required: 
      - title
      properties:
        title:
          type: string
          maxLength: 255
        description:
          type: string
          maxLength: 32000
        organization_id:
          type: integer
        posts_live_time:
          type: integer
        two_step_required:
          type: boolean
          default: false
        history_mode:
          type: string
          default: 'all'
        org_visible:
          type: boolean
          default: false
        allow_api:
          type: boolean
          default: true
        read_only:
          type: boolean
          default: false

    UpdateChat:
      type: object
      required: 
      - title
      properties:
        title:
          type: string
          maxLength: 255
        description:
          type: string
          maxLength: 32000
        posts_live_time:
          type: integer
        two_step_required:
          type: boolean
          default: false
        history_mode:
          type: string
          default: 'all'
        org_visible:
          type: boolean
          default: false
        allow_api:
          type: boolean
          default: true
        read_only:
          type: boolean
          default: false

    Chat:
      type: object
      required: 
      - title
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: string
        organization_id:
          type: integer
        posts_live_time:
          type: integer
        two_step_required:
          type: boolean
        history_mode:
          type: string
        org_visible:
          type: boolean
        allow_api:
          type: boolean
        read_only:
          type: boolean
        posts_count:
          type: integer
        pm:
          type: boolean
        e2e:
          type: boolean
        time_created:
          type: string
        time_updated:
          type: string
        time_edited:
          type: string
        author_id:
          type: integer
        tnew:
          type: boolean
        adm_flag:
          type: boolean
        custom_title:
          type: string
        is_favorite:
          type: boolean
        inviter_id:
          type: integer
        tshow:
          type: boolean
        user_time_edited:
          type: string
        history_start:
          type: integer
        pinned:
          type: array
          items:
            type: integer
        member_ids:
          type: array
          items:
            type: integer
        admin_ids:
          type: array
          items:
            type: integer
        group_ids:
          type: array
          items:
            type: integer
        guests:
          type: array
          items:
            type: integer
        thread_users:
          type: array
          items:
            type: integer
        thread_admins:
          type: array
          items:
            type: integer
        thread_groups:
          type: array
          items:
            type: integer
        last_msg:
          type: string
        last_read_post_no:
          type: integer
        last_msg_author_id:
          type: integer
        last_msg_author:
          type: string
        last_msg_bot_name:
          type: string
        last_msg_text:
          type: string
    
    Chats:
      type: object
      properties:
        chats:
          type: array
          items:
            $ref: "#/components/schemas/Chat"
                      
    ChatIds:
      type: object
      properties:
        chats:
          type: array
          items:
            type: integer

    ChatId:
      type: object
      properties:
        chat_id:
          type: integer

    Fork:
      type: object
      properties:
        posts:
          type: array
          items:
            type: integer
        title:
          type: string
          maxLength: 255
        description:
          type: string
          maxLength: 32000

    Users:
      type: object
      properties:
        users:
          type: array
          items:
            $ref: "#/components/schemas/User"

    User:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        unique_name:
          type: string
        info:
          type: string
        info_parsed:
          type: array
          items:
            type: object
        deleted:
          type: boolean
        active:
          type: boolean
        time_updated:
          type: string
        time_created:
          type: string
        is_bot:
          type: boolean
        organizations:
          type: array
          items:
            type: integer

    TeamIds:
      type: object
      properties:
        ids:
          type: array
          items:
            type: integer

    TeamId:
      type: object
      properties:
        org_id:
          type: integer
            
    Teams:
      type: object
      properties:
        orgs:
          type: array
          items:
            $ref: "#/components/schemas/Team"

    Team:
      type: object
      properties:
        id:
          type: integer
        slug:
          type: string
        title:
          type: string
        description:
          type: string
        description_parsed:
          type: array
          items:
            type: object
        email_domain:
          type: string
        time_created:
          type: string
        time_updated:
          type: string
        two_step_required:
          type: boolean
        default_chat_id:
          type: integer
        is_member:
          type: boolean
        is_admin:
          type: boolean
        state:
          type: string
        inviter_id:
          type: integer
        guests:
          type: array
          items:
            type: integer
        users:
          type: array
          items:
            type: integer
        admins:
          type: array
          items:
            type: integer
        groups:
          type: array
          items:
            type: integer

    TeamCreate:
      type: object
      properties:
        slug:
          type: string
        title:
          type: string
        description:
          type: string
        two_step_required:
          type: boolean
        email_domain:
          type: array
          items:
            type: string
            
    TeamUpdate:
      type: object
      properties:
        slug:
          type: string
        title:
          type: string
        description:
          type: string
        two_step_required:
          type: boolean
        two_step_disable_for_chats:
          type: boolean
        email_domain:
          type: array
          items:
            type: string

    TeamDelete:
      type: object
      properties:
        totp:
          type: string
        code:
          type: string

    ValidatioError:
      type: object
      properties:
        tamtam_response_api:
          type: boolean
        error:
          type: string
        codes:
          type: object
          properties:
            rng:
              type: string
        field_errors:
          type: object
          properties:
            rng:
              type: string

    NoAccess:
      type: object
      properties:
        code:
          type: string
        message:
          type: string