---
openapi: 3.1.2
info:
  title: pollen API
  version: 3.5.2
paths:
  /v2/status:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PollenStatus"
      summary: Get Status
      operationId: status
      tags:
        - Health
  /v2/logout:
    delete:
      responses:
        '204':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UndefinedResponse"
      operationId: logout
      tags:
        - Auth
  /v2/login:
    post:
      parameters:
        - name: Authorization
          in: header
          schema:
            type: string
          required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PollenUserId"
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '500':
          $ref: '#/components/responses/500'
      operationId: login
      tags:
        - Auth
  /v2/user:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PollenUser"
        '401':
          $ref: '#/components/responses/401'
        '500':
          $ref: '#/components/responses/500'
      summary: Get Connected User
      operationId: getConnectedUser
      tags:
        - User
  /v2/users/{userId}:
    get:
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
            format: UserId
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PollenUser"
        '401':
          $ref: '#/components/responses/401'
        '404':
          $ref: '#/components/responses/404'
        '500':
          $ref: '#/components/responses/500'
      summary: Get User
      operationId: getUser
      tags:
        - User
  /v2/polls:
    get:
      parameters:
        - name: search
          in: query
          schema:
            type: string
          required: false
        - name: usage
          in: query
          schema:
            $ref: '#/components/schemas/PollGetUsage'
          required: false
        - name: filter
          in: query
          schema:
            $ref: '#/components/schemas/PollGetFilter'
          required: false
        - name: pageNumber
          in: query
          schema:
            type: integer
            format: int32
        - name: pageSize
          in: query
          schema:
            type: integer
            format: int32
        - name: order
          in: query
          schema:
            type: string
        - name: desc
          in: query
          schema:
            type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaginatedPolls"
        '401':
          $ref: '#/components/responses/401'
        '500':
          $ref: '#/components/responses/500'
      summary: List polls
      operationId: getPolls
      tags:
        - Poll
  /v2/polls/{pollId}/comments:
    get:
      parameters:
        - name: pollId
          in: path
          required: true
          schema:
            type: string
            format: PollId
        - name: pageNumber
          in: query
          schema:
            type: integer
            format: int32
        - name: pageSize
          in: query
          schema:
            type: integer
            format: int32
        - name: order
          in: query
          schema:
            type: string
        - name: desc
          in: query
          schema:
            type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaginatedComments"
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '500':
          $ref: '#/components/responses/500'
      summary: List poll comments
      operationId: getPollComments
      tags:
        - Comment
    post:
      parameters:
        - name: pollId
          in: path
          required: true
          schema:
            type: string
            format: PollId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CommentInputs"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CommentRef"
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '500':
          $ref: '#/components/responses/500'
      summary: Create poll comment
      operationId: createPollComment
      tags:
        - Comment
  /v2/polls/{pollId}/comments/{commentId}:
    put:
      parameters:
        - name: pollId
          in: path
          required: true
          schema:
            type: string
            format: PollId
        - name: commentId
          in: path
          required: true
          schema:
            type: string
            format: CommentId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CommentInputs"
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CommentRef"
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '500':
          $ref: '#/components/responses/500'
      summary: Update existing poll comment
      operationId: updatePollComment
      tags:
        - Comment
    delete:
      parameters:
        - name: pollId
          in: path
          required: true
          schema:
            type: string
            format: PollId
        - name: commentId
          in: path
          required: true
          schema:
            type: string
            format: CommentId
      responses:
        '204':
          $ref: '#/components/responses/204'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '500':
          $ref: '#/components/responses/500'
      summary: Delete poll comment
      operationId: deletePollComment
      tags:
        - Comment
  /v2/resources/{resourceId}/preview:
    get:
      parameters:
        - name: resourceId
          in: path
          required: true
          schema:
            type: string
            format: ResourceId
        - name: maxDimension
          in: query
          schema:
            type: boolean
          required: false
      responses:
        '200':
          description: OK
          content:
            application/octet-stream:
              schema:
                $ref: "#/components/schemas/UndefinedResponse"
        '401':
          $ref: '#/components/responses/401'
        '500':
          $ref: '#/components/responses/500'
      summary: Get resource preview
      operationId: getPreview
      tags:
        - Resource
components:
  responses:
    '204':
      description: No Content
    '400':
      description: Bad Request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    '401':
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    '403':
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    '404':
      description: Not Found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    '500':
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'

  schemas:
    AppStatus:
      type: object
      properties:
        version:
          type: string
        commitId:
          type: string
        buildDate:
          type: string
    PersistenceStatus:
      type: object
      properties:
        nbPolls:
          type: integer
          format: int64
        errors:
          type: array
          items:
            type: string
    PollenStatus:
      type: object
      properties:
        app:
          $ref: "#/components/schemas/AppStatus"
        runtime:
          $ref: "#/components/schemas/RuntimeStatus"
        persistence:
          $ref: "#/components/schemas/PersistenceStatus"
    RuntimeStatus:
      type: object
      properties:
        jvmName:
          type: string
        javaVersion:
          type: string
        availableProcessors:
          type: integer
          format: int32
        loadAverage:
          type: number
          format: double
        memoryAllocated:
          type: string
        memoryUsed:
          type: string
        memoryFree:
          type: string
        memoryMax:
          type: string
        charset:
          type: string
        zoneId:
          type: string
        runningSince:
          type: string
          format: date-time
        uptime:
          type: string
    PollGetUsage:
      type: string
      enum:
        - ALL
        - INVITED
        - PARTICIPATED
        - CREATED
    PollGetFilter:
      type: string
      enum:
        - NONE
        - PAST
        - CURRENT
        - UPCOMING
    Pagination:
      type: object
      properties:
        count:
          type: integer
          format: int64
        currentPage:
          type: integer
          format: int32
        lastPage:
          type: integer
          format: int32
        pageSize:
          type: integer
          format: int32
        order:
          type: string
        desc:
          type: boolean
    PaginatedPolls:
      type: object
      required:
        - elements
        - pagination
      properties:
        elements:
          type: array
          items:
            $ref: "#/components/schemas/PollSummary"
        pagination:
          $ref: "#/components/schemas/Pagination"
    PollStatus:
      type: string
      enum:
        - CREATED
        - VOTING
        - ADDING_CHOICES
        - CLOSED
    PollSummary:
      type: object
      required:
        - id
        - title
        - status
        - creatorName
        - voteCount
      properties:
        id:
          type: string
        title:
          type: string
        permission:
          type: string
        status:
          $ref: "#/components/schemas/PollStatus"
        creatorAvatar:
          type: string
        creatorName:
          type: string
        voteCount:
          type: integer
          format: int64
        description:
          type: string
        beginDate:
          type: string
          format: date-time
        endDate:
          type: string
          format: date-time
        picture:
          type: string
        builtinPicture:
          type: string
    PollenUserId:
      type: object
      required:
        - id
      properties:
        id:
          type: string
    PollenUser:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: string
        name:
          type: string
        avatar:
          type: string
        defaultEmailAddress:
          type: string
    UndefinedResponse:
      type: null
    PaginatedComments:
      type: object
      required:
        - elements
        - pagination
      properties:
        elements:
          type: array
          items:
            $ref: "#/components/schemas/Comment"
        pagination:
          $ref: "#/components/schemas/Pagination"
    CommentInputs:
      type: object
      required:
        - authorName
        - text
      properties:
        authorName:
          type: string
        text:
          type: string
    Comment:
      type: object
      allOf:
        - $ref: "#/components/schemas/CommentInputs"
      required:
        - id
        - postDate
      properties:
        id:
          type: string
        permission:
          type: string
        authorAvatar:
          type: string
        postDate:
          type: string
          format: date-time
    CommentRef:
      type: object
      required:
        - id
      properties:
        id:
          type: string
        permission:
          type: string

    ApiError:
      type: object
      description: Error
      properties:
        name:
          type: string
          description: unique name of the error.
        correlation_id:
          type: string
          description: Internal identifier used for correlation purposes
        arguments:
          type: array
          description: The argument of the reason for the error.
          items:
            type: string
        details:
          description: Additional details for the error.
          type: array
          items:
            $ref: "#/components/schemas/ApiErrorDetail"
      required:
        - name
        - correlation_id

    ApiErrorDetail:
      type: object
      description: Additional details for the error.
      properties:
        value:
          type: string
          description: The value of the field that caused the error
        location:
          type: string
          description: The location of the field that caused the error.
        issue:
          type: string
          description: The reason for the error
        arguments:
          description: The argument of the reason for the error.
          type: array
          items:
            type: string
      required:
        - issue