openapi: 3.0.0
info:
  version: '0.0'
  title: Qomon
  description: |-
    This is Qomon's API definition.

    To get an authorization go to [Qomon's setting page](https://qomon.app/settings/extensions/connect) and create an API key.
servers:
  - description: Qomon production
    url: https://qomon.app/api
  - description: Qomon integration
    url: https://test.quorumapps.com/api
  - description: Qomon local
    url: http://localhost:8080


tags:
  - name: Session
    description: Login / Logout / Get current user
  - name: Security
    description: API key management
  - name: User
    description: Everything about users
  - name: New user
    description: Register new user
  - name: Teams
    description: Manage teams
  - name: Member invitation
    description: Manage user invitation
  - name: Role
    description: Everything about roles
  - name: Groups
    description: Everything about groups
  - name: Notifications
    description: Send notification to users

paths:
  /roles:
    get:
      tags:
        - Role
      summary: Retrieve role collection
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      count:
                        type: integer
                        example: 1
                      roles:
                        type: array
                        items:
                          $ref: '#/components/schemas/Role'
    post:
      tags:
        - Role
      summary: Create role
      description: |-
        Some fields will be ignored:
        - `id`
        - `group_id`
        - `type`
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: '#/components/schemas/Role'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      role:
                        $ref: '#/components/schemas/Role'
    patch:
      tags:
        - Role
      summary: Update role
      description: |-
        `type` fields will be ignored. `id` and `group_id` fields are required but can't be updated.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: '#/components/schemas/Role'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      role:
                        $ref: '#/components/schemas/Role'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "role_group_id_does_not_match"
        '404':
          description: Role not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "unknown_role"

  /roles/templates:
    get:
      tags:
        - Role
      summary: Retrieve the 4 role templates
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      count:
                        type: integer
                        example: 4
                      roles:
                        type: array
                        items:
                          $ref: '#/components/schemas/Role'
                        example:
                          - type: superadmin
                            web: true
                            access:
                              - documents:delete
                              - members:delete
                              - members.teams:delete
                              - import:write
                          - type: admin
                            web: true
                            access:
                              - documents:delete
                              - members:delete
                              - members.teams:delete
                          - type: manager
                            web: true
                            access:
                              - documents:read
                              - members:read
                              - members.teams:write
                          - type: user
                            web: false
                            access:
                              - documents:read
                              - members:read
  /roles/batch:
    patch:
      tags:
        - Role
      summary: Update role batch
      description: |-
        Some fields will be ignored:
        - `id`
        - `group_id`
        - `type`
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: array
                  items:
                    $ref: '#/components/schemas/Role'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      roles:
                        type: array
                        items:
                          $ref: '#/components/schemas/Role'
        '207':
          description: Partially successful response, some roles were not updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      roles:
                        type: array
                        items:
                            anyOf:
                              - $ref: '#/components/schemas/Role'
                              - type: object
                                properties:
                                  index:
                                    type: integer
                                    example: 1
                                  error:
                                    type: string
                                    example: "role_group_id_does_not_match"
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      roles:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                              example: 0
                            error:
                              type: string
                              example: "role_group_id_does_not_match"

  /roles/{id}:
    delete:
      tags:
        - Role
      summary: Delete role
      parameters:
        - name: id
          in: path
          schema:
            type: integer
          required: true
          example: '1259'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: "Successfully deleted"
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "unknown_role"
        '404':
          description: Role not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "unknown_role"
  /users/updateRole:
    patch:
      tags:
        - Role
      summary: Update user's role
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  required: [user_id,role_id]
                  properties:
                    user_id:
                      type: integer
                      example: 1244
                    role_id:
                      type: integer
                      example: 1244
                    advanced_search:
                      type: object
                      description: allows you to limit access to a scope of contacts
                      example: {
                          "query": {
                              "$all": [
                                  {
                                      "$all": [
                                          {
                                              "$condition": {
                                                  "ope": "not_eql",
                                                  "attr": "address.pollingstation",
                                                  "value": "United States"
                                              }
                                          }
                                      ]
                                  }
                              ]
                          }
                      }
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: "Successfully updated"
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "unknown_role_id"
        '404':
          description: User not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "unknown_user_id"

  /member-invitations:
    post:
      tags:
        - Member invitation
      summary: Invite by mail
      description: |-
        Send an invitation to the specified mail addresses.
        <br>If the mail address is already registered, the user will be added to the group.
        <br>If the mail address is not registered, the user will be invited to join the group.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [data]
              properties:
                data:
                  type: object
                  required: [invitations]
                  properties:
                    invitations:
                      type: array
                      items:
                        required: [email]
                        properties:
                          email:
                            type: string
                            example: "pedro@example.com"
                          role_id:
                            type: integer
                            example: 6
                          saved_filter_id:
                            type: integer
                            example: 1
                          emailer_sender_ids:
                            type: array
                            items:
                              type: integer
                            example: [101, 202, 303]
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      invitations:
                        type: array
                        items:
                          $ref: '#/components/schemas/MemberInvitationLight'
        '207':
          description: Multiple status response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      invitations:
                        type: array
                        items:
                          $ref: '#/components/schemas/MemberInvitationLight'
                      msg:
                        type: string
                        example: "some invitations created successfully"
                      errors: 
                        type: array
                        description: "List of errors if some invitations failed"
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                              example: 1
                              description: "Index of the invitation in the request"
                            error:
                              type: string
                              example: "role does not exist"
                            status:
                              type: integer
                              example: 400
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "role does not exist"
    get:
      tags:
        - Member invitation
      summary: Retrieve all invitations of the group
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      invitations:
                        $ref: '#/components/schemas/MemberInvitation'
    delete:
      tags:
        - Member invitation
      summary: Delete invitation
      parameters:
        - name: invitation_id
          in: query
          schema:
            type: integer
          example: '217'
      responses:
        '200':
          description: Successful response

  /session:
    post:
      tags:
        - Session
      summary: Login
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: "example@example.org"
                password:
                  type: string
                  example: "password"
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: ""
        '400':
          description: Bad request or wrong password
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 400
                      message:
                        type: string
                        example: "wrong password"
        '403':
          description: User don't have access to web app
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 403
                      message:
                        type: string
                        example: "user don't have the permission to access the webapp"
        '404':
          description: User not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 404
                      message:
                        type: string
                        example: "record not found"
        '412':
          description: "2FA : email validation resent"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: string
                    example: "2FA : email validation resent"
        '426':
          description: User don't have a group
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 426
                      message:
                        type: string
                        example: "user don't have a cause"
                      token:
                        type: string
    delete:
      tags:
        - Session
      summary: Logout
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: ""
  /me:
    get:
      tags:
        - Session
      summary: Get current user
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      user:
                        $ref: '#/components/schemas/User'
    patch:
      tags:
        - Session
      summary: Switch group
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                mail:
                  type: string
                  example: "john.doe@example.org"
                selected_group_id:
                  type: integer
                  example: 1
                UpdateToken:
                  type: boolean
                  enum:
                    - true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: "Successfully updated"
  /password/recover:
    post:
      tags:
        - Session
      summary: Send password recovery mail
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                mail:
                  type: string
                  example: "john.doe@example.org"
      responses:
        '200':
          description: Successful response
  /password/validation:
    post:
      tags:
        - Session
      summary: Validate password recovery
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                mail:
                  type: string
                  example: "john.doe@example.org"
                code:
                  type: string
                  example: "1234"
                  description: "The code received by mail"
                password:
                  type: string
                  example: "password"
                  description: "The new password"
      responses:
        '200':
          description: Successful response

  /users:
    post:
      tags:
        - User
      summary: List group users
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                limit:
                  type: integer
                  example: 10000
                offset:
                  type: integer
                  example: 0
                sort:
                  type: boolean
                  example: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      count:
                        type: integer
                        example: 1
                      users:
                        type: array
                        items:
                          $ref: '#/components/schemas/User'
  /users/{id}:
    get:
      tags:
        - User
      summary: Get user
      parameters:
        - name: id
          in: path
          schema:
            type: integer
          required: true
          example: '3737'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      user:
                       $ref: '#/components/schemas/User'
    patch:
      tags:
        - User
      summary: Update user
      parameters:
        - name: id
          in: path
          schema:
            type: integer
          required: true
          example: '3737'
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/UserView'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: "Successfully updated"
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      context:
                        type: string
                        example: "Unable to retrieve user"
                      error:
                        type: string
                        example: "record not found"
    delete:
      tags:
        - User
      summary: Delete user
      parameters:
        - name: id
          in: path
          schema:
            type: integer
          required: true
          example: '3737'
      responses:
        '200':
          description: Successful response
          content:
            application/json: {}
  /user/mail:
    get:
      tags:
        - New user
      summary: Check if mail is available
      parameters:
        - $ref: '#/components/parameters/MailParams'
      responses:
        '200':
          description: Mail is available
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: string
                    example: "Mail dispo."
        '401':
          description: Mail is not available
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: error
                  data:
                    type: string
                    example: "Ce mail existe déjà."
  /newuser:
    post:
      tags:
        - New user
      summary: Register new user
      requestBody:
        content: {}
      parameters:
        - $ref: '#/components/parameters/MailParams'
        - $ref: '#/components/parameters/PasswordParams'
        - $ref: '#/components/parameters/FirstNameParams'
        - $ref: '#/components/parameters/SurnameParams'
        - $ref: '#/components/parameters/PhoneParams'
        - $ref: '#/components/parameters/LocaleParams'
        - $ref: '#/components/parameters/GlobalCauseParams'
        - $ref: '#/components/parameters/AdressParams'

      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      token:
                        type: string
    patch:
      tags:
        - New user
      summary: Update new user
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/UserView'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: string
                    example: "Successfully updated"
  /user/validation:
    post:
      tags:
        - New user
      summary: Validate user email for new users or 2FA code
      description: |-
        Validate the user email address.
        <br>The code is sent by mail.
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                mail:
                  type: string
                  example: "john.doe@example.org"
                code:
                  type: string
                  example: "1234"
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    description: "The validation token"
  /users/password:
    patch:
      tags:
        - User
      summary: Update password
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                old_password:
                  type: string
                  example: "password"
                new_password:
                  type: string
                  example: "password"
                mail:
                  type: string
                  example: "john.doe@example.com"
      responses:
        '200':
          description: Successful response
        '403':
          description: Old password is wrong
  /users/update2fa:
    patch:
      tags:
        - User
      summary: Update 2fa activation
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                two_factor_enable:
                  type: boolean
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: string
                    example: "Successfully updated 2FA"
  /userkpi:
    get:
      tags:
        - User
      summary: Get KPIs about users
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      UserKpi:
                        type: object
                        properties:
                          NbVisites:
                            type: integer
                            example: 20
                          NbVisitesTermines:
                            type: integer
                            example: 20
        default:
          description: Unsuccessful operation

  /mygroup:
    get:
      tags:
        - Groups
      summary: Retrieve my group
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      group:
                        $ref: '#/components/schemas/Group'
    patch:
      tags:
        - Groups
      summary: Update data map title
      requestBody:
        content:
          application/json:
            schema:
              type: object
              example:
                status: success
                data:
                  group:
                    data_map_root_label: Zone géo
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      group:
                        $ref: '#/components/schemas/Group'
  /mygroups:
    get:
      tags:
        - Groups
      summary: List all groups
      description: >
        In body response, for each groups there is also the role object of the
        user in the corresponding group.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      groups:
                        type: array
                        items:
                          "allOf":
                            - $ref: '#/components/schemas/Group'
                            - type: object
                              properties:
                                role:
                                  $ref: '#/components/schemas/Role'
  /joincause:
    post:
      tags:
        - Groups
      summary: New user join a cause
      description: |-
        Allow to new users to join their first group.
        <br>The token to put in Bearer authentification to join a cause
        is transmitted by POST /sessions with 426 status code.
      security:
        - joincauseToken: []
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                code:
                  type: string
                  example: "invitationcode"
                  description: "This code is transmitted by an admin of the cause"
                mail:
                  type: string
                  example: "john.doe@example.org"
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      user:
                        $ref: '#/components/schemas/User'
        '404':
          description: Cause not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: string
                        example: "bad value"
  /getagecategories:
    get:
      tags:
        - Groups
      summary: Get age categories
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      age_categories:
                        type: array
                        items:
                          type: object
                          properties:
                            group_id:
                              type: integer
                              example: 123
                            id_category:
                              type: integer
                              example: 321
                            lower_year:
                              type: integer
                              example: 0
                            upper_year:
                              type: integer
                              example: 18
  /users/grantspace/{userId}:
    post:
      tags:
        - Groups
      summary: Add user to current group
      parameters:
        - name: userId
          in: path
          schema:
            type: integer
          required: true
          example: '3737'
      responses:
        '200':
          description: Successful response
  /subdivisions/{globalCause}:
    get:
      tags:
        - Groups
      summary: Retrieve all subdivisions of a global cause
      parameters:
        - name: globalCause
          in: path
          schema:
            type: string
          required: true
          example: 'eelv'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: array
                    items:
                      type: string
                      example: "bretagne"

  /teams/retrieve:
    post:
      tags:
        - Teams
      summary: Retrieve team collection by group
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      teams:
                        type: array
                        items:
                          $ref: '#/components/schemas/Team'
  /teams/retrieve_by_user:
    post:
      tags:
        - Teams
      summary: Retrieve team collection by user
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      teams:
                        type: array
                        items:
                          $ref: '#/components/schemas/Team'
  /teams-by-group-id:
    get:
      tags:
        - Teams
      summary: Retrieve team collection by group without users
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                      example: 123
                    CreatedAt:
                      type: string
                      format: date-time
                      example: "2022-10-13T15:50:34.643724Z"
                    UpdatedAt:
                      type: string
                      format: date-time
                      example: "2022-10-13T15:55:12.853724Z"
                    DeletedAt:
                      type: string
                      format: date-time
                      example:
                    name:
                      type: string
                      example: "Team 1"
                    group_id:
                      type: integer
                      example: 123
  /teams:
    post:
      tags:
        - Teams
      summary: Create team
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    team:
                      $ref: '#/components/schemas/TeamCreation'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      team:
                        $ref: '#/components/schemas/Team'
    patch:
      tags:
        - Teams
      summary: Update team
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Team'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      team:
                        $ref: '#/components/schemas/Team'
    delete:
      tags:
        - Teams
      summary: Delete team
      parameters:
        - name: id
          in: query
          schema:
            type: integer
          required: true
          example: '123'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      team_id:
                        type: integer
                        example: 123
                      message:
                        type: string
                        example: "team successfully deleted"
  /choose-team:
    post:
      tags:
        - Teams
      summary: Choose team
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                team:
                  type: object
                  properties:
                    id:
                      type: integer
                      example: 123
                user:
                  type: object
                  properties:
                    id:
                      type: integer
                      example: 3714
      responses:
        '200':
          description: Successful response
  /teams/leave/{id}:
    delete:
      summary: Leave a team
      parameters:
        - name: id
          in: path
          schema:
            type: integer
          required: true
          example: '1259'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      message:
                        type: string
                        example: "Team successfully left"
                      team_id:
                        type: integer
                        example: 1259
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: "not integer"
        '403':
          description: Role not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "error"
                  data:
                    type: object
                    properties:
                      error:
                        type: string
                        example: "record not found"

  /global-message:
    post:
      tags:
        - Notifications
      summary: Send notification to teams
      description: |-
        Send a notification to all users of the teams.
        The notification will be displayed in the mobile app.
        If `team_ids` isn't specified, the notification will be sent to all users of the group.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    body:
                      type: string
                      example: "Last miles"
                    title:
                      type: string
                      example: "Action-focused"
                    team_ids:
                      type: array
                      items:
                        type: integer
                      example: [123, 124]
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      accepted:
                        type: boolean
                        example: true

  /access_token:
    post:
      tags:
        - Security
      summary: Create an access token
      description: |-
        User need to be already logged with the same account and need to be at least an admin
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                username:
                  type: string
                password:
                  type: string
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    $ref: "#/components/schemas/AccessToken"
        401:
          description: Wrong password
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      code:
                        type: integer
                        example: 401
                      message:
                        type: string
                        example: wrong password
        default:
          description: Unsucessful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
    get:
      tags:
        - Security
      summary: List access tokens
      description: |-
        User need to be at least an admin
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/AccessToken"
        default:
          description: Unsucessful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
    delete:
      tags:
        - Security
      summary: Revoke an access tokens
      description: |-
        User need to be at least an admin
      parameters:
        - name: access_token
          in: query
          description: Access Token to be revoked
          required: true
          schema:
            type: string
      responses:
        200:
          description: Successful operation
        default:
          description: Unsucessful operation

  /notification-settings:
    get:
      tags:
        - Notifications
      summary: Retrieve notification settings
      description: |-
        Retrieve notification settings for the current user
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      available_types:
                        type: array
                        items:
                          type: string
                          example: ["push", "email", "sms"]
                      current:
                        type: object
                        properties:
                          id:
                            type: integer
                          user_id:
                            type: integer
                          push:
                            type: boolean
                            format: nullable
                          email:
                            type: boolean
                            format: nullable
                          sms:
                            type: boolean
                            format: nullable
    post:
      tags:
        - Notifications
      summary: Update notification settings
      description: |-
        Update notification settings for the current user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    push:
                      type: boolean
                    email:
                      type: boolean
                    sms:
                      type: boolean
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      id:
                        type: integer
                      user_id:
                        type: integer
                      push:
                        type: boolean
                        format: nullable
                      email:
                        type: boolean
                        format: nullable
                      sms:
                        type: boolean
                        format: nullable

  /notifications:
    get:
      tags:
        - Notifications
      summary: Retrieve users notifications
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        event:
                          type: string
                          example: "ExportDone"
                        created_at:
                          type: string
                        data:
                          type: object
                          properties:
                            body:
                              type: string
                              example: "Un export est disponible"
                            title:
                              type: string
                              example: "Un export est disponible"


components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    cookieAuth:
      type: apiKey
      in: cookie
      name: SID
    joincauseToken:
      type: http
      scheme: bearer
      description: "Token to join a cause transmitted by POST /sessions with 426"

  parameters:
    MailParams:
      in: query
      name: mail
      schema:
        type: string
        example: "new.user@example.org"
    PasswordParams:
      in: query
      name: password
      schema:
        type: string
        example: "password"
    FirstNameParams:
      in: query
      name: firstname
      schema:
        type: string
        example: "John"
    SurnameParams:
      in: query
      name: surname
      schema:
        type: string
        example: "Doe"
    PhoneParams:
      in: query
      name: phone
      schema:
        type: string
        example: "0123456789"
    LocaleParams:
      in: query
      name: locale
      schema:
        type: string
        example: "fr"
    RoleParams:
      in: query
      name: role
      schema:
        type: string
        example: "user"
        oneOf:
          - type: string
            enum: ["user", "manager", "admin", "superadmin"]
    GlobalCauseParams:
      in: query
      name: global_cause
      schema:
        type: string
        example: "cause"
    AdressParams:
      in: query
      name: address
      schema:
        type: string
        example: "1 rue de la paix"
        description: "Street address"
    PostalCodeParams:
      in: query
      name: postal
      schema:
        type: string
        example: "75000"
        description: "Postal code"
    CityParams:
      in: query
      name: city
      schema:
        type: string
        example: "Paris"
        description: "City"
    LocationParams:
      in: query
      name: locale
      schema:
        type: string
        example: "fr"
        description: "Locale"
    GdprAccepted:
      in: query
      name: gdpr_accepted
      schema:
        type: boolean
        example: true
        description: "GDPR accepted"

  schemas:
    RoleWithoutAccessList:
      type: object
      properties:
        id:
          type: integer
          example: 1452
        group_id:
          type: integer
          example: 123
        type:
          type: string
          example: "superadmin"
        color:
          type: string
          example: "#1097C5"
        order:
          type: integer
          example: 1
        web:
          type: boolean
        mobile:
          type: boolean

    Role:
      allOf:
        - $ref: '#/components/schemas/RoleWithoutAccessList'
        - type: object
          properties:
            access:
              type: array
              items:
                type: array
                items:
                  type: string
              example: ["contacts:read", "contacts:write", "contacts:delete"]

    UserView:
      type: object
      properties:
        firstname:
          type: string
          example: "John"
        surname:
          type: string
          example: "Doe"
        mail:
          type: string
          example: "example@example.org"
        phone:
          type: string
          example: "0123456789"
        locale:
          type: string
          example: "fr"
        role:
          type: string
          example: "user"
        global_cause:
          type: string
          example: "cause"
        address:
          type: string
          example: "1 rue de la paix"
        postal:
          type: string
          example: "75000"
        city:
          type: string
          example: "Paris"
        location:
          type: string
          example: "fr"
        gdpr_accepted:
          type: boolean
          example: true

    User:
      allOf:
        - $ref: '#/components/schemas/UserWithoutRole'
        - type: object
          properties:
            role_data:
              $ref: '#/components/schemas/Role'

    UserWithoutRoleAccess:
      allOf:
        - $ref: '#/components/schemas/UserWithoutRole'
        - type: object
          properties:
            role_data:
              $ref: '#/components/schemas/RoleWithoutAccessList'

    UserWithoutRole:
      type: object
      properties:
        id:
          type: integer
        CreatedAt:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        UpdatedAt:
          type: string
          format: date-time
          example: "2022-10-13T15:55:12.853724Z"
        birthdate:
          type: string
          format: date-time
        created:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        firstname:
          type: string
          example: "John"
        surname:
          type: string
          example: "Doe"
        selected_group_id:
          type: array
          items:
            type: integer
          example: [1]
        group_id:
          type: array
          items:
            type: integer
          example: [1, 2, 4]
        locale:
          type: string
          example: "en"
        mail:
          type: string
          example: "john.doe@example.org"
        phone:
          type: string
          example: "0123456789"
        role:
          type: string
          example: "superadmin"
        two_factor_enable:
          type: boolean
        validationcode:
          type: string
          example:
        gdpr_accepted:
          type: boolean

    Team:
      type: object
      properties:
        id:
          type: integer
          example: 40
        name:
          type: string
          example: "Team 1"
        CreatedAt:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        UpdatedAt:
          type: string
          format: date-time
          example: "2022-10-13T15:55:12.853724Z"
        DeletedAt:
          type: string
          format: date-time
          example:
        group_id:
          type: integer
          example: 123
        users:
          type: array
          items:
            $ref: '#/components/schemas/UserWithoutRoleAccess'

    TeamCreation:
      type: object
      properties:
        name:
          type: string
          example: "Team 1"
        users:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
          example:
            - id: 123
            - id: 124
            - id: 125

    Group:
      type: object
      properties:
        action_aggreg_without_location:
          type: boolean
        action_type_color:
          type: string
          format: nullable
        allow_multiple_team_select:
          type: boolean
        allow_team_select:
          type: boolean
        archi_data_carto:
          type: string
        around_me_disabled:
          type: boolean
        auto_join:
          type: boolean
        avatar_company:
          type: string
        avatar_company_m_to_w:
          type: string
        befree_uuid:
          type: string
        check_doublon:
          type: boolean
        code_cause:
          type: string
        code_edit_form:
          type: string
        code_edit_form_enabled:
          type: boolean
        consent_sms_with_url:
          type: boolean
        create_absent_contacts_enabled:
          type: boolean
        create_refused_contacts_enabled:
          type: boolean
        custom_parameters:
          type: object
          properties:
            mobile:
              type: object
              properties:
                enable_data_priority:
                  type: boolean
            webapp:
              type: object
              properties:
                main_menu_urls:
                  type: array
                  items:
                    type: object
                    properties:
                      label:
                        type: string
                      url:
                        type: string
        dashboardUrl:
          type: string
        data_authorized_scales:
          type: array
          items:
            type: string
        data_geo_root_code:
          type: string
        data_map_contours_scale:
          type: string
        data_map_root_label:
          type: string
        data_parent_territories_administrative_ids:
          type: string
        data_parent_territories_scale:
          type: string
        disable_autourdesoi:
          type: string
        disable_import_search_for_duplicate:
          type: boolean
        double_optin_sms_enable:
          type: boolean
        email_referent:
          type: string
        endofcampain:
          type: string
          format: date-time
        features:
          type: object
          properties:
            actions:
              type: object
              properties:
                behavior_new_contact_added_on_static_canvassing:
                  type: string
                call_creation:
                  type: string
                canvassing_creation:
                  type: string
                event_creation:
                  type: string
                gotvcalling_creation:
                  type: string
                gotvcanvassing_creation:
                  type: string
                mail_creation:
                  type: string
                mail_creation_display_option_only_streets_unknown:
                  type: string
                other_creation:
                  type: string
                reporting_creation:
                  type: string
                sharing_creation:
                  type: string
                static_creation:
                  type: string
                web_access_actions:
                  type: string
            analytics:
              type: object
              properties:
                analytics_dashboard_tab:
                  type: string
                web_access_analytics:
                  type: string
            cartography:
              type: object
              properties:
                data_explorator:
                  type: string
                web_access_data_insights:
                  type: string
                web_access_data_profiles:
                  type: string
            communication:
              type: object
              properties:
                web_access_communication:
                  type: string
                web_access_global_notification:
                  type: string
                web_access_messages_email:
                  type: string
                web_access_messages_sms:
                  type: string
            consent:
              type: object
              properties:
                mobile_consent_add_new_contact:
                  type: string
                mobile_consent_launch_survey:
                  type: string
            contacts:
              type: object
              properties:
                add_fast_contact_launch_survey_opportunities:
                  type: string
                advanced_search:
                  type: string
                anonymous_survey:
                  type: string
                home_redirection_after_answered_survey:
                  type: string
                web_access_custom_fields:
                  type: string
                web_management_duplicates:
                  type: string
                web_massive_delete:
                  type: string
            documents:
              type: object
              properties:
                web_access_documents:
                  type: string
            export_contacts:
              type: object
              properties:
                web_export_contacts:
                  type: string
                web_management_duplicates:
                  type: string
            forms:
              type: object
              properties:
                number_status_forms:
                  type: string
                type_status_forms:
                  type: string
            forms_typologies:
              type: object
              properties:
                qr_code:
                  type: string
            import_contacts:
              type: object
              properties:
                web_import_contacts:
                  type: string
            members:
              type: object
              properties:
                web_access_members_invitations:
                  type: string
                web_access_members_teams:
                  type: string
                web_display_labels_members_badges:
                  type: string
            online_forms:
              type: object
              properties:
                web_access_online_forms:
                  type: string
            petitions:
              type: object
              properties:
                web_access_customisation:
                  type: string
                web_access_petitions:
                  type: string
            quickactions:
              type: object
              properties:
                mobile_add_contact_quickaction:
                  type: string
                mobile_quick_actions_access:
                  type: string
            survey:
              type: object
              properties:
                mobile_blacklist_on_refusal:
                  type: string
                mobile_display_comeback_refusal_forms:
                  type: string
                mobile_display_follow_ups:
                  type: string
                web_access_auto_email:
                  type: string
                web_access_auto_sms:
                  type: string
                web_access_survey:
                  type: string
                web_access_survey_contact_detail:
                  type: string
                web_dashboard_survey:
                  type: string
                web_dashboard_survey_access_admin:
                  type: string
            tasks:
              type: object
              properties:
                web_access_tasks:
                  type: string
            web_access_roles:
              type: object
              properties:
                mobile_application:
                  type: string
                mobile_option_enable_look_for_contacts_nearby:
                  type: string
                web_access_roles:
                  type: string
            web_settings:
              type: object
              properties:
                mobile_application:
                  type: string
                mobile_option_enable_look_for_contacts_nearby:
                  type: string
                web_access_roles:
                  type: string
        geocodage_country:
          type: string
        geocodage_language:
          type: string
        geocodage_service:
          type: string
        global_cause:
          type: string
        hierarchy:
          type: string
        id:
          type: integer
        level_id:
          type: string
        locale:
          type: string
        mailchimp_apikey:
          type: string
        mailjetapipublickey:
          type: string
        mailjetapisecretkey:
          type: string
        metabase_api_key:
          type: string
        must_have_double_optin_sms:
          type: boolean
        must_have_optin_email:
          type: boolean
        must_have_optin_sms:
          type: boolean
        name:
          type: string
        nationbuilder_apikey:
          type: string
        nationbuilder_nation:
          type: string
        nb_event_synchro:
          type: boolean
        optout_sms_enable:
          type: boolean
        originator:
          type: string
        package_name:
          type: string
        restrict_archi_data_carto_to:
          type: string
          format: nullable
        root_scope:
          type: object
        saved_prio:
          type: array
          items:
            type: object
            properties:
              _computedLocked:
                type: boolean
              _uniqueId:
                type: string
              computed_possible_scales:
                type: array
                items:
                  type: string
              default:
                type: boolean
              elements:
                type: array
                items:
                  type: object
              items:
                type: array
                items:
                  type: object
              label:
                type: string
              type:
                type: string
              weight:
                type: integer
        scope:
          type: string
        sendinblue_apikey:
          type: string
        sms_accountsid:
          type: string
        sms_authtoken:
          type: string
        space_main_goal:
          type: string
        stop_sms_number:
          type: string
        sublevel_id:
          type: string
        type:
          type: string
        url_base_map:
          type: string
        url_satellite_map:
          type: string
        zone:
          type: string

    MemberInvitationLight:
      type: object
      properties:
        id:
          type: integer
        CreatedAt:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        user_id:
          type: integer
        group_id:
          type: integer
        email:
          type: string
          example: "john.doe@example.org"
        mobile_phone:
          type: string
          example: "0123456789"
        role_id:
          type: integer
        saved_filter_id:
          type: integer

    MemberInvitation:
      allOf:
        - $ref: '#/components/schemas/MemberInvitationLight'
        - type: object
          properties:
            role:
              $ref: '#/components/schemas/Role'
            saved_filter:
              type: object
              properties:
                id:
                  type: integer
                group_id:
                  type: integer
                title:
                  type: string
                  example: "My list"
                created_at:
                  type: string
                  format: date-time
                  example: "2022-10-13T15:50:34.643724Z"
                updated_at:
                  type: string
                  format: date-time
                  example: "2022-10-13T15:50:34.643724Z"
                user_id:
                  type: integer
                payload:
                  type: string
                  format: json
                  description: "Advanced search stringified"
                  example: '{"$all":[{"$all":[{"$condition":{"attr":"firstname","ope":"eql","value":"Paul"}}]}]}'
                is_favorite:
                  type: boolean
                is_segment:
                  type: boolean

    AccessToken:
      type: object
      properties:
        access_token:
          type: string
          example: CcpyJ_zURN2T5PvJ6jK6jw
        created_at:
          type: string
          example: 2023-11-15T16:12:07.232781151Z
        expiration_date:
          type: string
          example: 2025-01-05T08:12:07.231100199Z
        group_id:
          type: integer
          example: 1
        user_id:
          type: integer
          example: 15315
        label:
          type: string
          example: An access key


security:
  # - cookieAuth: []
  - bearerAuth: []