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
tags:
  - name: Contacts
    description: Everything about contacts
  - name: Search
    description: Search contacts
  - name: Lists
    description: Everything about contacts lists
  - name: Interactions
    description: Everything interactions with a contact
  - name: Notes
    description: Everything about notes linked to a contact
  - name: Form data
    description: |-
      Everything about form data linked to a contact.
      Form data are the answers to a form filled by a contact.
  - name: Bulk edit contacts
    description: Massive update and delete of contacts
  - name: Exports
    description: Manage contact exports
  - name: Imports
    description: Manage contact imports
  - name: Materials
    description: Manage document and attachments
  - name: Actions
    description: Everything about actions
  - name: SMS
    description: Send sms to contacts

paths:
  /contacts:
    post:
      tags:
        - Contacts
      summary: Create a contact
      description: |-
        Some fields will be ignored:
        - `id`
        - `group_id`
        - `CreatedAt`/`UpdatedAt`

        The routes for custom fields / form data is in the setting open api file
      operationId: createContact
      requestBody:
        description: Update an existent contact
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [data]
              properties:
                data:
                  type: object
                  required: [contact]
                  properties:
                    contact:
                      $ref: "#/components/schemas/Contact"
            examples:
              basic:
                value:
                  data:
                    contact:
                      firstname: John
                      surname: Doe
                      birthdate: '1999-12-31T23:00:00.000Z'
                      mail: john.doe@example.com
                      mobile: '0123456789'
                      address:
                        building: A
                        floor: '2'
                        door: '3'
                        housenumber: '123'
                        street: Rue de la paix
                        addition: Résidence de la paix
                        postalcode: '75001'
                        city: Paris
                        country: France
              full:
                value:
                  data:
                    contact:
                      gender: M
                      firstname: John
                      surname: Doe
                      married_name: Doe
                      birthdate: '1999-12-31T23:00:00.000Z'
                      birthcity: Paris
                      birthcountry: France
                      mail: john.doe@example.com
                      mobile: '0123456789'
                      phone: '0123456789'
                      address:
                        building: A
                        floor: '2'
                        door: '3'
                        housenumber: '123'
                        street: Rue de la paix
                        addition: Résidence de la paix
                        postalcode: '75001'
                        city: Paris
                        country: France
                      tags:
                        - name: tag1
                        - name: tag2
                      formdatas:
                        - form_id: 47566
                          form_ref_id: 15648
                          data: consent_email
                        - form_id: 879856
                          form_ref_id: 98746
                          data: "Yes"
                      custom_fields:
                        - form_id: 879856
                          form_ref_id: 98746
                          data: hamburger
                      black_list: false
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                required: [status, data]
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    required: [contact]
                    properties:
                      contact:
                        required: [id]
                        $ref: "#/components/schemas/Contact"
        default:
          description: Unsuccessful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"

  /contacts/{contactId}:
    get:
      tags:
        - Contacts
      summary: Find a contact by id
      operationId: getContactPerId
      parameters:
        - name: contactId
          in: path
          description: ID of contact to return
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      contact:
                        $ref: "#/components/schemas/Contact"
        "default":
          description: Unsuccessful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
    patch:
      tags:
        - Contacts
      summary: Update an existing contact by id
      description: |-
        Some fields will be ignored:
        - `id`
        - `group_id`
        - `CreatedAt`/`UpdatedAt`
      operationId: updateContactPerId
      parameters:
        - name: contactId
          in: path
          description: ID of contact to update
          required: true
          schema:
            type: integer
      requestBody:
        description: The new values of the contact
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    contact:
                      $ref: "#/components/schemas/Contact"
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      contact:
                        $ref: "#/components/schemas/Contact"
        "default":
          description: Unsuccessful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
    delete:
      tags:
        - Contacts
      summary: Delete a contact by id
      operationId: deleteContactPerId
      parameters:
        - name: contactId
          in: path
          description: ID of contact to delete
          required: true
          schema:
            type: integer
      responses:
        "204":
          description: Successful operation
  /contacts/{contactId}/tags:
    get:
      tags:
        - Contacts
      summary: Get tags of a contact
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to get tags from
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Tag"

  /contacts/{contactId}/interactions:
    get:
      tags:
        - Interactions
      summary: Get interactions of a contact
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to get interactions from
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Interaction"
    post:
      tags:
        - Interactions
      summary: Create an interaction
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to create an interaction for
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    interaction:
                      $ref: "#/components/schemas/Interaction"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      interaction:
                        $ref: "#/components/schemas/Interaction"
    patch:
      tags:
        - Interactions
      summary: Update an interaction
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to update interactions for
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    interaction:
                      $ref: "#/components/schemas/Interaction"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      interaction:
                        $ref: "#/components/schemas/Interaction"
  /contacts/{contactId}/interactions/{id}:
    delete:
      tags:
        - Interactions
      summary: Delete an interaction
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to delete interactions for
          required: true
          schema:
            type: integer
        - name: id
          in: path
          description: ID of the interaction to delete
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Successful operation

  /contacts/{contactId}/notes:
    get:
      tags:
        - Notes
      summary: Get notes of a contact
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to get notes from
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Note"
    post:
      tags:
        - Notes
      summary: Create a note
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to create a note for
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    note:
                      type: object
                      properties:
                        data:
                          type: string
                        only_super_admin:
                          type: boolean
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      note:
                        $ref: "#/components/schemas/Note"
  /contacts/{contactId}/notes/{noteId}:
    get:
      tags:
        - Notes
      summary: Get one note of a contact
      parameters:
        - $ref: "#/components/parameters/contactId"
        - $ref: "#/components/parameters/noteId"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      note:
                        $ref: "#/components/schemas/Note"
    patch:
      tags:
        - Notes
      summary: Update a note
      parameters:
        - $ref: "#/components/parameters/contactId"
        - $ref: "#/components/parameters/noteId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    note:
                      type: object
                      properties:
                        data:
                          type: string
                        only_super_admin:
                          type: boolean
                        pinned:
                          type: boolean
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      note:
                        $ref: "#/components/schemas/Note"
    delete:
      tags:
        - Notes
      summary: Delete a note
      parameters:
        - $ref: "#/components/parameters/contactId"
        - $ref: "#/components/parameters/noteId"
      responses:
        '200':
          description: Successful operation

  /contacts/{contactId}/formdatas:
    get:
      tags:
        - Form data
      summary: Get form data of a contact
      parameters:
        - $ref: "#/components/parameters/contactId"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      formdatas:
                        type: array
                        items:
                          $ref: "#/components/schemas/FormData"
    post:
      tags:
        - Form data
      parameters:
        - $ref: "#/components/parameters/contactId"
      summary: Create a form data for a contact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    formdata:
                      type: object
                      properties:
                        form_id:
                          type: integer
                          example: 1178304
                        form_ref_id:
                          type: integer
                          example: 1542036
                        data:
                          type: integer
                          example: "Oui"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      formdata:
                        $ref: "#/components/schemas/FormData"
  /contacts/{formdataId}/formdatas/{anything}:
    get:
      tags:
        - Form data
      parameters:
        - $ref: "#/components/parameters/formdataId"
        - name: anything
          in: path
          description: Unused
          required: true
          schema:
            type: string
      summary: Get one form data
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      formdata:
                        $ref: "#/components/schemas/FormData"

  /contacts/{contactId}/formdatas/{formdataId}:
    patch:
      tags:
        - Form data
      parameters:
        - $ref: "#/components/parameters/contactId"
        - $ref: "#/components/parameters/formdataId"
      summary: Update a form data for a contact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    formdata:
                      type: object
                      properties:
                        form_id:
                          type: integer
                          example: 1178304
                        form_ref_id:
                          type: integer
                          example: 1542036
                        data:
                          type: integer
                          example: "Oui"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      formdata:
                        $ref: "#/components/schemas/FormData"

  /contacts/{anything}/formdatas/{formdataId}:
    delete:
      tags:
        - Form data
      description: Delete a form data
      parameters:
        - $ref: "#/components/parameters/formdataId"
        - name: anything
          in: path
          description: Unused
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Successfully deleted

  /contacts/{contactId}/history:
    get:
      tags:
        - Contacts
      summary: Get history of a contact
      description: |-
        The history tracks all the changes made to a contact. How it was created, updated, all interactions, etc.
      parameters:
        - $ref: "#/components/parameters/contactId"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    $ref: "#/components/schemas/History"
                example:
                  status: success
                  data:
                    - date_for_ordering: '2023-10-03T15:18:58.625495Z'
                      sms:
                        id: 56489
                        created: '2023-10-03T15:18:58.625495Z'
                        from: ASender
                        to: "+3312345678"
                        message: Merci d'avoir signé.
                        group_id: 1
                        status: delivered
                        messageuuid: 34c76428791f49ae835d4ce8169c77fc
                        campainid: 5577366b-b06e-4723-a968-ee3e3f81b3f0
                        number_of_credit_needed: 1
                        message_id_for_consent_url: 90ea726d-aa56-42df-b300-5a00cf1c6c88
                    - date_for_ordering: '2022-04-21T12:58:14.749326Z'
                      fact:
                        status: todo
                        type: Event of the year
                    - date_for_ordering: '2022-04-21T12:48:04.189136Z'
                      import:
                        ImportID: ca312b67-7352-4894-93a4-115357afef47
                        CreatedAt: '2022-04-21T12:48:04.189136Z'
                        Name: Doe
                        UserName: John

  /contacts/list:
    post:
      description: Upsert a list of contacts asynchronously
      summary: Upsert a list of contacts asynchronously
      tags:
        - Contacts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    contacts:
                      type: array
                      items:
                        $ref: "#/components/schemas/Contact"
      responses:
        '202': # Accepted
          description: Contacts are all enqueued for Upsert
        '207': # Multi-Status
          description: Some contacts are not enqueued for Upsert
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "fail"
                  data:
                    type: object
                    properties:
                      msg:
                        type: string
                        example: "fail to publish some contacts to upsert queue"
                      errors:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                              example: 5
                              description: Index of the contact in the request
                            msg:
                              type: string
                              example: "fail to publish contact"
                              description: Error message
        '400':
          description: Bad request
        '500':
          description: Internal server error, no contact has been enqueued

  /search/addresses:
    get:
      tags:
        - Search
      summary: Search among all contacts addresses.
      description: Search among all contacts addresses a match with a given query string.
      parameters:
        - name: query
          in: query
          description: The query string to search for.
          required: true
          schema:
            type: string
          example: "beaudras"
        - name: withPhone
          in: query
          description: Whether to include contacts with a phone number or not.
          required: false
          schema:
            type: boolean
            default: false
        - name: unknow
          in: query
          description: TODO
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    occurence:
                      type: string
                      description: The area (like city) where one or several addresses match the query.
                      example: reims
                    count:
                      type: integer
                      description: The number of contacts that match the query in the area.
                      example: 2
                    subentities:
                      type: array
                      description: The addresses that match the query in the area.
                      items:
                        type: object
                        properties:
                          occurence:
                            type: string
                            description: The address that match the query.
                            example: all jean beaudras
                          count:
                            type: integer
                            description: The number of contacts that match the query in the address.
                            example: 2

  /search:
    post:
      tags:
        - Search
      summary: Search for contacts
      description: |
        Search for contacts given a query

        Only the advanced search is documented
      requestBody:
        required: true
        description: "TODO: describe"
        content:
          application/json:
            schema:
              type: object
              required: [data]
              properties:
                data:
                  $ref: "#/components/schemas/Search"
            examples:
              Minimal Search:
                $ref: "#/components/examples/minimalSearch"
              Advanced Search simple:
                $ref: "#/components/examples/advancedSearchSimple"
              Advanced Search full:
                $ref: "#/components/examples/advancedSearchFull"
              Geographic Search:
                $ref: "#/components/examples/searchWithPolygon"

      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      contacts:
                        type: array
                        items:
                          $ref: "#/components/schemas/Contact"
        default:
          description: Unsuccessful operation

  /kpi:
    post:
      tags:
        - Search
      summary: Get KPIs about contacts
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [data]
              properties:
                data:
                  $ref: "#/components/schemas/Search"
            examples:
              Minimal Search:
                $ref: "#/components/examples/minimalSearch"
              Advanced Search simple:
                $ref: "#/components/examples/advancedSearchSimple"
              Advanced Search full:
                $ref: "#/components/examples/advancedSearchFull"
              Geographic Search:
                $ref: "#/components/examples/searchWithPolygon"
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      kpi:
                        type: array
                        items:
                          type: object
                          properties:
                            KpiReplies:
                              type: array
                              nullable: true
                              items:
                                type: object
                                properties:
                                  Key:
                                    type: string
                                  Doc_count:
                                    type: integer
                    example:
                      kpi:
                      - KpiReplies:
                        - Key: total
                          Doc_count: 22232
                      - KpiReplies:
                        - Key: f
                          Doc_count: 9549
                        - Key: m
                          Doc_count: 6672
                        - Key: a
                          Doc_count: 8
                        - Key: missing
                          Doc_count: 5972
                      - KpiReplies:
                        - Key: NOTRE DAME DES CHAMPS
                          Doc_count: 2463
                        - Key: Laon-Zola – Neufchâtel - Orgeval
                          Doc_count: 1466
                        - Key: Centre Ville
                          Doc_count: 1275
                        - Key: Chemin vert – clémenceau – Europe
                          Doc_count: 1275
                        - Key: Cernay – Epinettes – Jamin – Jaures
                          Doc_count: 1159
                        - Key: Barbatre – St Rémi – Verriere
                          Doc_count: 980
                        - Key: Charles Arnould – Clairmarais
                          Doc_count: 891
                        - Key: missing
                          Doc_count: 6017
  /kpi-presence-status:
    post:
      tags:
        - Search
      summary: Get KPIs about contacts presence status
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: "#/components/schemas/Search"
              example:
                data:
                  query: ''
                  fields:
                  - '561'
                  - all
                  - '50'
                  - '0'
                  - ''
                  - ''
                  - ''
                  - surname
                  - 'true'
                  - ''
                  - ''
                  - ''
                  polygon: []
                  tags: []
                  only_duplicates: false
                  address_included: []
                  polling_station_included: []
                  polling_station_included_missing: false
                  geohash_precision: 8
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      kpi:
                        type: array
                        items:
                          type: object
                          properties:
                            KpiReplies:
                              type: array
                              items:
                                type: object
                                properties:
                                  Key:
                                    type: string
                                  Doc_count:
                                    type: integer
                    example:
                      kpi:
                        - KpiReplies:
                          - Key: total
                            Doc_count: 335
                        - KpiReplies:
                          - Key: Convaincu(e)
                            Doc_count: 119
                          - Key: Indécis
                            Doc_count: 20
                          - Key: Non Convaincu(e)
                            Doc_count: 7
                          - Key: missing
                            Doc_count: 189

  /filters:
    post:
      tags:
        - Lists
      summary: Create a list
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    title:
                      type: string
                      example: "My list"
                    payload:
                      type: string
                      format: json
                      description: Advanced search payload stringified
                      example: '{"$all":[{"$all":[{"$condition":{"attr":"firstname","ope":"eql","value":"Paul"}}]}]}'
                    is_favorite:
                      type: boolean
                      example: false
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    $ref: "#/components/schemas/List"
    get:
      tags:
        - Lists
      summary: Get all lists
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/List"
    patch:
      tags:
        - Lists
      summary: Update a list
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  $ref: "#/components/schemas/List"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    $ref: "#/components/schemas/List"
    delete:
      tags:
        - Lists
      summary: Delete a list
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  $ref: "#/components/schemas/List"
      responses:
        "200":
          description: OK

  /massive-manipulations:
    post:
      tags:
        - Bulk edit contacts
      summary: Perform a massive delete of contacts
      description: It's an asynchronous operation.
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MassiveManipulationArgs"
            examples:
              With contact id list:
                value:
                  data:
                    contact_ids:
                      - 345678
                      - 234567
                      - 9876
                    fields:
                      - 1
                      - all
                description: "`fields: [ 1, \"all\"]` is mandatory"
      responses:
        "201":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    $ref: "#/components/schemas/MassiveManipulation"
    # delete:

  /massive-manipulations/status/{jobId}:
    get:
      tags:
        - Bulk edit contacts
      summary: Get detail and status of a massive delete by job id
      parameters:
        - name: jobId
          in: path
          description: ID of the job to get the status from
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/MassiveManipulation"
  /massive-manipulations/jobs:
    get:
      tags:
        - Bulk edit contacts
      summary: Get all detail and status of a massive delete of contacts
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/MassiveManipulation"
  /massive-manipulations/contact-status/{contactId}:
    get:
      tags:
        - Bulk edit contacts
      summary: Get status of a contact in a massive delete
      parameters:
        - name: contactId
          in: path
          description: ID of the contact to get the status from
          required: true
          example: 123456
          schema:
            type: integer
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      contact_id:
                        type: integer
                        example: 123456
                      enqueud_at:
                        type: string
                        format: date-time
                        example: "2023-11-29T09:30:39.341671287Z"
                      job_id:
                        type: integer
                        example: 254
                      deleted_at:
                        type: string
                        format: date-time
                        example: "2023-11-29T09:30:43.193647563Z"
  /metamorph:
    post:
      tags:
        - Bulk edit contacts
      summary: Perform a massive update of contacts
      description: It's an asynchronous operation.
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MetamorphArgs"
      responses:
        '201':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/Metamorph"
    get:
      tags:
        - Bulk edit contacts
      summary: Get all detail and status of a massive update of contacts
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/Metamorph"

  /contacts/transfer:
    post:
      tags:
        - Bulk edit contacts
      summary: Transfer contacts to another group
      description: |-
        Move contacts from one of the requesting user's currently selected groups to
        `target_group_id`. It's an asynchronous operation: contacts are transferred one
        by one in the background and `completedCount` on the returned job increases as
        they complete.

        At least one of `search.contact_ids` or `search.advanced_search` must be provided.
        When `search.advanced_search` is used, it's resolved server-side across every
        matching page (not just the page currently displayed), so a query alone is enough
        to transfer all matching contacts regardless of how many pages they span.
        `search.exclude_contacts` can be combined with `search.advanced_search` to transfer
        all matching contacts except a few.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [data]
              properties:
                data:
                  $ref: "#/components/schemas/TransferArgs"
            examples:
              With contact id list:
                value:
                  data:
                    search:
                      contact_ids:
                        - 345678
                        - 234567
                    target_group_id: 1888
              Select all pages matching a query:
                value:
                  data:
                    search:
                      advanced_search:
                        query:
                          $all:
                            - $condition:
                                attr: tags
                                ope: eql
                                value: to-transfer
                    target_group_id: 1888
              Select all pages except a few:
                value:
                  data:
                    search:
                      advanced_search:
                        query:
                          $all:
                            - $condition:
                                attr: tags
                                ope: eql
                                value: to-transfer
                      exclude_contacts:
                        - 345678
                    target_group_id: 1888
      responses:
        "201":
          description: Transfer job created
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/TransferJob"
        "400":
          description: Bad request (missing search criteria, or target_group_id not among the selected groups)
        "500":
          description: Internal server error

  /imports:
    get:
      tags:
        - Imports
      summary: Get all imports
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Import"
    post:
      tags:
        - Imports
      summary: Create an import
      description: Upload a file to create an import
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Import"
  /imports/{importId}:
    get:
      tags:
        - Imports
      summary: Get an import
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Import"
    delete:
      tags:
        - Imports
      summary: Archied an import
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: Successfully archived
          content:
            text/plain:
             schema:
                type: string
                example: OK
  /imports/{importId}/name:
    post:
      tags:
        - Imports
      summary: Update an import name
      parameters:
        - $ref: "#/components/parameters/importId"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: "My import"
      responses:
        "200":
          description: Successfully renamed
  /imports/{importId}/columns:
    get:
      tags:
        - Imports
      summary: Get columns names of the imported file
      parameters:
        - $ref: "#/components/parameters/importId"
        - $ref: "#/components/parameters/separatorExport"
        - $ref: "#/components/parameters/commentExport"
        - $ref: "#/components/parameters/startReadAtExport"
        - $ref: "#/components/parameters/columnIdxExport"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
                example: ["First Name","Last Name","Genre","Email","Mobile Phone","Street","City","country"]
  /imports/{importId}/file-preview:
    get:
      tags:
        - Imports
      summary: Get import preview
      description:
        Get the first 15 lines of the imported file
      parameters:
        - $ref: "#/components/parameters/importId"
        - $ref: "#/components/parameters/separatorExport"
        - $ref: "#/components/parameters/commentExport"
        - $ref: "#/components/parameters/startReadAtExport"
        - $ref: "#/components/parameters/columnIdxExport"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  description: A contact (a row in the imported file)
                  type: array
                  items:
                    type: string
                    description: Value of a column (a field of the contact)
  /imports/{importId}/csv-settings:
    post:
      tags:
        - Imports
      summary: Update CSV settings
      description: |-
        Set separator, comment, start_read_at and country for an import to allow
        the right interpretation of the imported file.
      parameters:
        - $ref: "#/components/parameters/importId"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                separator:
                  type: string
                  example: ";"
                comment:
                  type: string
                  example: "#"
                start_read_at:
                  type: string
                  example: "0"
                country:
                  type: string
                  example: "FRA"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Import"
  /imports/{importId}/sample-lines:
    get:
      tags:
        - Imports
      summary: Get a sample of the imported file
      description: |-
        Get the first 15 lines of the imported file
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  import_id:
                    type: string
                  sample_lines:
                    type: array
                    description: A row in the imported file
                    items:
                      type: array
                      description: Columns values
                      items:
                        type: string
                example:
                  import_id: 1cd82bcc-6d36-4560-b8a5-1cdff5e10749
                  sample_lines:
                    - ["First Name","Last Name","Genre","Email","Mobile Phone","Street","City","country"]
                    - ["Paul-Charles","Dupont","","","","","","France"]
                    - ["Paul-Hervé","Deschamp","","jbd+test@qomon.com","","","","France"]
  /imports/{importId}/properties:
    get:
      tags:
        - Imports
      summary: Supported keys
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
              example:
                - contact_id
                - tag
                - first_name
                - last_name
                - birth_date
                - house_number
                - street
                - city
                - email
                - gender
                - married_name
                - mobile
                - phone
                - age
                - additional_address_fields
                - postal_code
                - country
                - building
                - floor
                - door
                - birth_country
                - birth_city
                - polling_station
                - note
                - nationbuilderid
  /imports/{importId}/mapping:
    post:
      tags:
        - Imports
      summary: Set mapping between columns and contact fields
      description: Columns can be retrieved with the endpoint `/imports/{importId}/properties`
      parameters:
        - $ref: "#/components/parameters/importId"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MappingImportExport"
            examples:
              simple:
                value: {"first_name":1,"last_name":2,"gender":4,"phone":5,"email":6,"mobile":7,"street":8}
              full:
                value: {"additional":18,"age_category":8,"birthcity":7,"birthcountry":6,"birthdate":5,"black_list":25,"building":15,"city":20,"coordinates":22,"country":21,"created_at":29,"custom":31,"door":17,"email":9,"firstname":1,"floor":16,"forms":24,"gender":4,"housenumber":13,"id":0,"last_change":27,"last_updated_by":28,"married_name":3,"mobile":11,"notes":26,"phone":10,"pollingstation":12,"postal_code":19,"street":14,"surname":2,"tags":23,"updated_at":30}

      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Import"
  /imports/{importId}/enqueue:
    post:
      tags:
        - Imports
      summary: Enqueue an import
      parameters:
        - $ref: "#/components/parameters/importId"
        - name: channel
          in: query
          required: false
          schema:
            type: integer
            example: 1
      responses:
        "200":
          description: OK
  /imports/{importId}/statuses:
    get:
      tags:
        - Imports
      summary: Get import statuses
      description: List all steps of the import process with timestamps
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    status:
                      type: string
                      enum:
                        - created
                        - file_config_not_defined
                        - file_config_defined
                        - file_parsing_enqueued
                        - file_parsing_canceled
                        - file_parsing_wip
                        - file_parsing_done
                        - file_parsing_error
                        - search_conflicts_wip
                        - search_conflicts_done
                        - finalization_process_requested
                        - finalization_process_rejected
                        - finalization_process_enqueued
                        - finalization_process_wip
                        - finalization_process_done
                        - finalization_process_error
                      example: file_parsing_done
                    created_at:
                      type: string
                      format: date-time
                    description:
                      type: string
                      example: "total created: 4; total invalid: 0; total already exists: 0; total errors: 0"
  /imports/{importId}/resolve:
    post:
      tags:
        - Imports
      summary: Resolve import conflicts
      parameters:
        - $ref: "#/components/parameters/importId"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              required:
                - strategy
              type: object
              properties:
                strategy:
                  type: string
                  enum:
                    - ignore_conflicts
                    - create_new_profiles
                  nullable: false
      responses:
        202:
          description: Accepted

  /imports/{importId}/contact-creation-requests:
    get:
      tags:
        - Imports
      description: May be legacy
      parameters:
        - $ref: "#/components/parameters/importId"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ContactCreationRequest"
  /imports/{importId}/conflicts:
    get:
      tags:
        - Imports
      parameters:
        - $ref: "#/components/parameters/importId"
      description: May be legacy
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      format: uuid
                    level:
                      type: string
                    suggested_resolution:
                      type: string
                    resolved_at:
                      type: string
                      format: date-time
                    resolution_strategy:
                      type: string
                      nullable: false
                      enum:
                        - todo
                        - ignore
                        - create_new_profile
                        - merge_new_properties
                        - merge_old_properties
                    profile_id:
                      type: string
                      format: uuid
                    profile:
                      type: object
                    import_id:
                      type: string
                      format: uuid
                    contact_creation_request_id:
                      type: integer
                    contact_creation_request:
                      $ref: "#/components/schemas/ContactCreationRequest"
                    reasons:
                      type: array
                      items:
                        type: object
                        properties:
                          ID:
                            type: string
                            format: uuid
                          conflict_id:
                            type: string
                            format: uuid
                          label:
                            type: string

                    customer_account_id:
                      type: integer
        "422":
          description: Unprocessable Entity
          content:
            text/plain:
              schema:
                type: string
                example: "Unprocessable Entity (import status is not search_conflicts_done)"

  /xlsx-export:
    get:
      tags:
        - Exports
      summary: Get export list
      responses:
        "200":
          description: Successful operation
        default:
          description: Unsucessful operation
    post:
      summary: Create an export
      description: |
        TODO:
          - mapping
          - search
          - directmail
          - credentials
          - export to s3
          - repeat every / start at

        To add your credentials for an export to an S3, please ask support.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: "#/components/schemas/ExportArgs"

      tags:
        - Exports
      responses:
        200:
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    $ref: "#/components/schemas/Export"
  /download-export/{exportId}:
    get:
      tags:
        - Exports
      summary: Download an export
      parameters:
        - name: exportId
          in: path
          description: ID of the export to download
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Successful operation
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
          headers:
            Content-Disposition:
              schema:
                type: string
                example: attachment; filename="export-2020-11-30T14:00:00.000Z.xlsx"

  /docs/category:
    post:
      tags:
        - Materials
      summary: Create a document category
      description: |-
        Create a document category

        Id is ignored in the payload

        Order must be unique across document categories
      operationId: createDocCategory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: "#/components/schemas/DocumentCategory"
            examples:
              Create document category:
                value:
                  data:
                    label: Video
                    order: 1
      responses:
        "201":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/DocumentCategory"
        default:
          description: "Unsuccessful operation"
    patch:
      tags:
        - Materials
      summary: Update a document category
      description: |-
        Update a document category

        Id must not be null / empty, null or empty values are ignored
      operationId: updateDocCategory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  $ref: "#/components/schemas/DocumentCategory"
            examples:
              Update doc category:
                value:
                  data:
                    id: 4
                    label: Category
                    order: 1
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/DocumentCategory"
              examples:
                Update doc category:
                  value:
                    data:
                      id: 4
                      group_id: 1
                      label: Category
                      order: 1
        default:
          description: "Unsuccessful operation"
  /docs/category/{id}:
    delete:
      tags:
        - Materials
      summary: Delete a document category by id
      description: |-
        Delete doc category if the category is not used in a document

        The operation is a no-op  if the category is used in a document
      operationId: deleteDocCategory
      parameters:
        - name: id
          in: path
          description: ID of the document category to delete
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: "#/components/schemas/DocumentCategory"
              examples:
                Update doc category:
                  value:
                    data:
                      id: 4
                      group_id: 1
                      label: Category
                      order: 1
        default:
          description: "Unsuccessful operation"
  /docs/categories:
    patch:
      tags:
        - Materials
      summary: Mass edit document categories
      description: Mass edit document categories
      operationId: massEditDocCategories
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: array
                  items:
                    $ref: "#/components/schemas/DocumentCategory"
            examples:
              Mass edit doc categories:
                value:
                  data:
                    - group_id: 1
                      id: 4
                      label: Category v2 order 2
                      order: 2
                    - group_id: 1
                      id: 40
                      label: image chat v2 order 1
                      order: 1
                    - group_id: 1
                      id: 41
                      label: "categorie screen v2 "
                      order: 4
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/DocumentCategory"
              examples:
                Mass edit doc categories:
                  value:
                    data:
                      - group_id: 1
                        id: 4
                        label: Category v2 order 2
                        order: 2
                      - group_id: 1
                        id: 40
                        label: image chat v2 order 1
                        order: 1
                      - group_id: 1
                        id: 41
                        label: "categorie screen v2 "
                        order: 4
        default:
          description: "Unsuccessful operation"
    get:
      tags:
        - Materials
      summary: List document categories
      description: List document categories
      operationId: listDocCategories
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/DocumentCategory"
              examples:
                List of all documents:
                  value:
                    data:
                      - group_id: 1
                        id: 4
                        label: Category v2 order 2
                        order: 2
                      - group_id: 1
                        id: 40
                        label: image chat v2 order 1
                        order: 1
                      - group_id: 1
                        id: 41
                        label: "categorie screen v2 "
                        order: 4
        default:
          description: Unsuccessful operation
  /docs:
    post:
      tags:
        - Materials
      summary: Search documents
      description: Search documents
      operationId: searchDocuments
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    File:
                      type: object
                      properties:
                        minimum_role:
                          type: string
                          example: user
                        private:
                          type: boolean
                          example: false
            examples:
              Search documents:
                value:
                  data:
                    File:
                      minimum_role: user
                      private: false
      responses:
        "200":
          description: ""
  /uploaddoc:
    post:
      tags:
        - Materials
      summary: Upload a new document
      description: Upload a new document
      operationId: uploadANewDocument
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                category:
                  type: string
                cover:
                  type: string
                  description: An url to the cover of the document
                doc_category_id:
                  type: string
                is_interaction:
                  type: string
                minimum_role:
                  type: string
                  description: Can be user, admin, superadmin, manager
                notify:
                  type: string
                  description: Send a notification when the file has been uploaded
                private:
                  type: string
                subject:
                  type: string
                type:
                  type: string
                  description: 'Either "youtube" if the url is a youtube link or the mime type'
                url:
                  type: string
                  description: The url of the file
                file:
                  type: string
                  description: The file as a multipart form
            examples:
              Upload a new document:
                value:
                  category: ""
                  cover: ""
                  doc_category_id: "1"
                  file: ""
                  is_interaction: "false"
                  minimum_role: ""
                  notify: ""
                  private: ""
                  subject: ""
                  type: ""
                  url: ""
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    $ref: "#/components/schemas/Document"
  /uploaddoc/notify:
    post:
      tags:
        - Materials
      summary: Notify members that a document has been uploaded
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  description: The id of the document
            examples:
              Notify a document:
                value:
                  id: 2045
      responses:
        "204":
          description: "Successful operation"
          
  /doc/{id}:
    get:
      tags:
        - Materials
      summary: Get a document by id
      description: Get a document
      operationId: getDocument
      parameters:
        - name: id
          in: path
          description: ID of the document to fetch
          required: true
          schema:
            type: integer
            example: 2045
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      file:
                        $ref: "#/components/schemas/Document"
    delete:
      tags:
        - Materials
      summary: Delete a document
      description: Delete a document
      operationId: deleteADocument
      parameters:
        - name: id
          in: path
          description: ID of the document to delete
          required: true
          schema:
            type: integer
            example: 2045
      responses:
        "200":
          description: ""
    patch:
      tags:
        - Materials
      summary: Patch document
      description: Patch document
      operationId: patchDocument
      parameters:
        - name: id
          in: path
          description: ID of the document to update
          required: true
          schema:
            type: integer
            example: 2045
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                category:
                  type: string
                cover:
                  type: string
                doc_category_id:
                  type: string
                minimum_role:
                  type: string
                private:
                  type: string
                subject:
                  type: string
            examples:
              Update a document:
                value:
                  category: ""
                  cover: ""
                  doc_category_id: "1"
                  minimum_role: ""
                  private: ""
                  subject: ""
          multipart/form-data:
            schema:
              type: object
              properties:
                doc-category:
                  type: string
                  example: "2"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      file:
                        $ref: "#/components/schemas/Document"


  /actionsfilterbygroup:
    get:
      tags:
        - Actions
      summary: Get actions filter by group
      description: Get actions filter by group
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      ActionsAggreg:
                        type: array
                        items:
                          $ref: "#/components/schemas/ActionAgreg"
  /actionsfilterbyuser:
    get:
      tags:
        - Actions
      summary: Get actions filter by user
      description: Get actions filter by user
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      ActionsAggreg:
                        type: array
                        items:
                          $ref: "#/components/schemas/ActionAgreg"
  /globalaction:
    get:
      tags:
        - Actions
      summary: Get global actions
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      ActionsAggreg:
                        type: array
                        items:
                          $ref: "#/components/schemas/ActionAgreg"
  /actions:
    post:
      tags:
        - Actions
      summary: Create an action
      description: |-
        Omit empty fields to keep the current value
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    action:
                      $ref: "#/components/schemas/ActionArgs"
            examples:
              Create an action:
                $ref: "#/components/examples/action"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      action:
                          $ref: "#/components/schemas/Action"
    patch:
      tags:
        - Actions
      summary: Update / Terminate / Soft delete an action
      description: |-
        Possible actions:
        - Soft delete: status `archived` (all fields are ignored except `ID` and `status`)
        - Terminate: status `finished` (all fields are ignored except `ID` and `status`)
        - Update: change any field
        <br><br>Omit empty fields to keep the current value
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  $ref: "#/components/schemas/ActionArgs"
            examples:
              Soft delete:
                value:
                  data:
                    ID: 45239
                    status: archived
              Terminate:
                value:
                  data:
                    ID: 45239
                    status: finished
              Update:
                  ID: 4155
                  $ref: "#/components/examples/actionID"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      action:
                          $ref: "#/components/schemas/Action"
  /actions/{actionId}:
    get:
      tags:
        - Actions
      summary: Get an action by id
      parameters:
        - $ref: "#/components/parameters/actionId"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      action:
                        $ref: "#/components/schemas/Action"
  /actions/{actionId}/setActivity:
    post:
      tags:
        - Actions
      summary: Set user activity in an action
      parameters:
        - $ref: "#/components/parameters/actionId"
        - name: status
          in: query
          description: Status of the user in the action
          required: true
          schema:
            type: string
            enum:
              - active
              - inactive
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      action:
                        $ref: "#/components/schemas/Action"
  /action-participation-reminder:
    post:
      tags:
        - Actions
      summary: Send a reminder to participate in an action
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action_id:
                  type: integer
                  description: ID of the action
                  example: 2880
      responses:
        "202":
          description: Successful accepted
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      accepted:
                        type: boolean

  /action/{actionId}/files:
    get:
      tags:
        - Actions
      summary: Get files of an action
      parameters:
        - $ref: "#/components/parameters/actionId"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      actions:
                        type: object
                        properties:
                          id:
                            type: integer
                          group_id:
                            type: integer
                          files:
                            type: array
                            items:
                              $ref: "#/components/schemas/Document"
    post:
      tags:
        - Actions
      summary: Set files of an action. 
      description: Replace existing files with new ones. Remove all associations if empty.
      parameters:
        - $ref: "#/components/parameters/actionId"
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    files:
                      type: array
                      items:
                        type: object
                        properties:
                          id:
                            type: integer
                            description: ID of the file
                            example: 2045
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      actions:
                        type: object
                        properties:
                          id:
                            type: integer
                          group_id:
                            type: integer
                          files:
                            type: array
                            items:
                              $ref: "#/components/schemas/Document"   
    delete:
      tags:
        - Actions
      summary: Clear files of an action (remove association)
      parameters:
        - $ref: "#/components/parameters/actionId"
      responses:
        '204':
          description: Successful operation

  /public-actions/{globalCause}:
    get:
      tags:
        - Actions
      summary: Get public actions by global cause
      parameters:
        - name: globalCause
          in: path
          description: Global cause of the action
          required: true
          schema:
            type: string
            example: eelv
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      ActionsAggreg:
                        type: array
                        items:
                          $ref: "#/components/schemas/ActionAgreg"
  /public-actions/{globalCause}/{subdivision}:
    get:
      tags:
        - Actions
      summary: Get public actions by global cause and subdivision
      parameters:
        - name: globalCause
          in: path
          description: Global cause of the action
          required: true
          schema:
            type: string
            example: "ecologie"
        - name: subdivision
          in: path
          description: Subdivision of the action
          required: true
          schema:
            type: string
            example: bretagne
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      ActionsAggreg:
                        type: array
                        items:
                          $ref: "#/components/schemas/ActionAgreg"

  

components:
  responses:
    BadRequest:
      description: Invalid request, such as lacking required request body or parameter
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: User authenticated but does not have permission to access the requested resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The specified resource was not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: User must authenticate before using this api
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnexpectedError:
      description: An internal error occured
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer

  parameters:
    contactId:
      name: contactId
      in: path
      description: ID of a contact
      required: true
      schema:
        type: integer
        example: 83854766
    formdataId:
      name: formdataId
      in: path
      description: ID of a formdata
      required: true
      schema:
        type: integer
        example: 1178304
    actionId:
      name: actionId
      in: path
      description: ID of an action
      required: true
      schema:
        type: integer
        example: 45239
    noteId:
      name: noteId
      in: path
      description: ID of a note
      required: true
      schema:
        type: integer
        example: 45239
    importId:
      name: importId
      in: path
      description: ID of an import
      required: true
      schema:
        type: integer
    separatorExport:
      name: separator
      in: query
      description: The separator used in the imported file
      required: true
      schema:
        type: string
        example: ";"
    commentExport:
      name: comment
      in: query
      description: The comment character used in the imported file
      required: true
      schema:
        type: string
        example: "#"
    startReadAtExport:
      name: start_read_at
      in: query
      description: The line number where to start reading the imported file
      required: true
      schema:
        type: string
        example: "0"
    columnIdxExport:
      name: column_idx
      in: query
      description: The column index where to start reading the imported file
      required: true
      schema:
        type: string
        example: "0"

  examples:
    action:
      value:
        data:
          name: Construire un immeuble
          type_data: static
          pitch: Il faut commencer par contruire des maisons
          status: todo
          goal: 2
          start: '2023-11-30T06:00:00Z'
          end: '2024-11-21T23:00:00Z'
          group_id: 1
          fields: '["1","all","0","0","","","","surname","true","","",""]'
          polygon: "[]"
          notify: true
          users:
          - id: 3714
          teams:
          - id: 470
          addresses:
          - street: Rue de la paix
            postalcode: '75000'
            city: Paris
            housenumber: '12'
          Forms:
          - id: 4250
            label: brief
            refvalues:
            - id: 6648
              CreatedAt: '2022-09-16T14:50:41.390952Z'
              UpdatedAt: '2023-11-27T13:41:54.292355Z'
              form_id: 4250
              label: Good brief
              min: 0
          public: false
    actionID:
      value:
        data:
          ID: 4155
          name: Construire un immeuble
          type_data: static
          pitch: Il faut commencer par contruire des maisons
          status: todo
          goal: 2
          start: '2023-11-30T06:00:00Z'
          end: '2024-11-21T23:00:00Z'
          group_id: 1
          fields: '["1","all","0","0","","","","surname","true","","",""]'
          polygon: "[]"
          notify: true
          users:
          - id: 3714
          teams:
          - id: 470
          addresses:
          - street: Rue de la paix
            postalcode: '75000'
            city: Paris
            housenumber: '12'
          Forms:
          - id: 4250
            label: brief
            refvalues:
            - id: 6648
              CreatedAt: '2022-09-16T14:50:41.390952Z'
              UpdatedAt: '2023-11-27T13:41:54.292355Z'
              form_id: 4250
              label: Good brief
              min: 0
          public: false
    minimalSearch:
      value:
        data:
          search:
            advanced_search:
              query:
                $all: []
    advancedSearchSimple:
      value:
        data:
          advanced_search:
            page: 0
            per_page: 50
            query:
              "$all":
                - "$at_least_one":
                  - "$condition":
                      attr: address.city
                      ope: eql
                      value: Bordeaux
                  - "$condition":
                      attr: address.city
                      ope: eql
                      value: Talence
                  - "$condition":
                      attr: address.city
                      ope: eql
                      value: Mérignac
            sort_asc: true
            sort_attr: surname
      description: |-
        <b>Search contacts with:</b>
        <br>(address.city is equal to Bordeaux
        <br>OR address.city is equal to Talence
        <br>OR address.city is equal to Mérignac)
    advancedSearchFull:
      value:
        data:
          advanced_search:
            page: 0
            per_page: 50
            query:
              "$all":
              - "$at_least_one":
                - "$condition":
                    attr: mobile
                    ope: ext
                - "$condition":
                    attr: phone
                    ope: ext
              - "$all":
                - "$condition":
                    attr: form
                    form_id: 4530
                    form_ref_ids:
                    - 7486
                    ope: eql
                    value:
              - "$all":
                - "$condition":
                    attr: form
                    form_id: 544
                    form_ref_ids:
                    - 6420
                    ope: eql
                    value:
              - "$all":
                - "$condition":
                    attr: custom_fields
                    form_id: 782
                    form_ref_ids:
                    - 8392
                    ope: eql
                    value: ok
            sort_asc: true
            sort_attr: surname
      description: |-
        <b>Search contacts with:</b>
        <br>(mobile exist OR phone exist)
        <br>AND (ref value of form 4530 is equal to 7486)
        <i>-> (ex: form 4530 is "Consentement RGPD" and ref value 7486 is "OK for call and SMS")</i>
        <br>AND (ref value of form 544 is equal to 6420)
        <i>-> (ex: form 544 is "Level of support" and ref value 6420 is "indecisive")</i>
        <br>AND (ref value of form 782 is equal to 8392)
        <i>-> (ex: form 782 is "A custom field" and ref value 8392 is "ok")</i>
    searchWithPolygon:
      value:
        data:
          polygon:
            - lat: 49.093008625245375
              lng: 1.4886983421166633
            - lat: 49.09139942022449
              lng: 1.487141996299158
            - lat: 49.09134577915847
              lng: 1.4911557302476695
            - lat: 49.093008625245375
              lng: 1.4886983421166633
          fields: ["427", "all"]
      description: |-
        Search contacts in an area defined by geographic
        coordinates. The area is defined by a polygon (array of points).

  schemas:
    Error:
      allOf:
        - $ref: '#/components/schemas/ResponseError'
        - type: object
          required:
            - message
          properties:
            message:
              description: A human readable error message usually considered presentable on user interfaces
              type: string
    ResponseError:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum:
            - error
            - fail
    ResponseSuccess:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum:
            - success
    
    Contact:
      type: object
      properties:
        id:
          type: integer
          example: 83854766
        group_id:
          type: integer
          example: 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"
        lastchange:
          type: string
          example: "2022-10-13T15:50:24.163Z"
        firstname:
          type: string
          example: "Jeanne"
        surname:
          type: string
          example: "Dupont"
        married_name:
          type: string
          example: "Dupont"
        gender:
          type: string
          example: "F"
        birthdate:
          type: string
          format: date-time
          example: "1955-07-06T00:00:00Z"
        age_category:
          type: integer
        birthdept:
          type: string
        birthcity:
          type: string
        birthcountry:
          type: string
        mail:
          type: string
          format: email
        phone:
          type: string
        mobile:
          type: string
        address:
          $ref: "#/components/schemas/Address"
        tags:
          type: array
          items:
            $ref: "#/components/schemas/Tag"
        links:
          type: array
          items:
            type: object
        actions_ids:
          type: array
          items:
            type: integer
        user_id:
          type: integer
        formdatas:
          type: array
          items:
            $ref: "#/components/schemas/FormData"
        customfields:
          type: array
          items:
            type: object
        black_list:
          type: boolean
          description: Prevent any communication with this contact.
          example: true
        notes:
          type: array
          items:
            type: object
            required:
              - content
            properties:
              id:
                type: integer
              content:
                type: string
              pinned:
                type: boolean

    Address:
      type: object
      properties:
        id:
          type: integer
          example: 8971
        housenumber:
          type: string
          example: "1"
        street:
          type: string
          example: "rue de la paix"
        postalcode:
          type: string
          example: "75000"
        citycode:
          type: string
          example: "75101"
        city:
          type: string
          example: "Paris"
        state:
          type: string
          example: "Ile-de-France"
        country:
          type: string
          example: "France"
        addition:
          type: string
          example: "Résidence de la paix"
        infos:
          type: string
          example: "Porte de gauche"
        building:
          type: string
          example: "Bâtiment A"
        floor:
          type: string
          example: "2"
        door:
          type: string
          example: "A"
        pollingstation:
          type: string
          example: "BV-06"
        score:
          type: number
          example: 0.965753
        latitude:
          type: string
          example: "48.869476"
        longitude:
          type: string
          example: "2.02458"
        location:
          type: string
          example: "48.869476,2.02458"
        invalid:
          type: boolean
          nullable: true
          example: null

    FormData:
      description: |-
        A formdata is a response to a form. It links a contact, a form and a refvalue.
        <br>A contact (`contact_id`) anwser to a form (`form_id`) by selecting
        a refvalue (`form_ref_id`) with a value (`data`).
      type: object
      properties:
        id:
          type: integer
          example: 1178304
        created_at:
          type: string
          format: date-time
          example: "2022-10-13T15:50:24.163Z"
        updated_at:
          type: string
          format: date-time
          example: "2022-10-13T15:50:24.163Z"
        deleted_at:
          type: string
          format: date-time
          example: "2022-10-13T15:50:24.163Z"
          nullable: true
        data:
          type: string
          example: "Oui"
        date:
          type: string
          format: date-time
          example: "2022-10-13T15:50:24.163Z"
        donedate:
          type: string
          format: date-time
          nullable: true
          example: null
        label:
          type: string
          nullable: true
          example: null
        type_of_form:
          type: string
          nullable: true
          example: null
        group_id:
          type: integer
          example: 4567
        contact_id:
          type: integer
          example: 83854766
          description: ID of the contact
        form_id:
          type: integer
          example: 97885
          description: "ID of the form"
        form_ref_id:
          type: integer
          example: 1542036
          description: "ID of the refvalue of the form"

    Document:
      type: object
      properties:
        id:
          type: integer
          example: 2045
        created:
          type: string
          example: 2023-11-16T10:26:30.295882Z
        owner_id:
          type: integer
          example: 1261
        subject:
          type: string
          example: Home pets
        group_id:
          type: integer
          example: 1
        type:
          type: string
          example: image/png
        minimum_role:
          type: string
          example: user
        url:
          type: string
          example: https://file-qomon.s3.fr-par.scw.cloud/AUTH_1015284cd1294d24921707984b4c219c/XCHWdsKvWnsTMoibBgtz/Capture_d_e_cran_2023_09_27_a__11_14_47_png
        mime:
          type: string
          example: image/png
        name:
          type: string
          example: Capture_d_e_cran_2023_09_27_a__11_14_47_png
        folder:
          type: string
          example: XCHWdsKvWnsTMoibBgtz
        category:
          type: string
          example: internal
        doc_category_id:
          type: integer
          example: 43
        cover:
          type: string
          example: https://avatars-qomon.s3.fr-par.scw.cloud/group_avatars/fdf28459-03e0-49b2-b43b-7eb9cdeafd18.png
    DocumentCategory:
      type: object
      properties:
        id:
          type: integer
          example: 4
        group_id:
          type: integer
          example: 1
        label:
          type: string
          example: Video
        order:
          type: integer
          example: 1

    Tag:
      type: object
      properties:
        name:
          type: string
        appearance_count:
          type: integer
        color:
          type: string

    User:
      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
          format: email
          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
    UserWithoutRoleLight:
      allOf:
        - $ref: "#/components/schemas/User"
        - type: object
          properties:
            role_data:
              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
    UserWithActive:
      allOf:
        - $ref: "#/components/schemas/User"
        - type: object
          properties:
            active:
              type: boolean
              example: true

    Teams:
      type: object
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
          example: "Team 1"
        group_id:
          type: integer
          example: 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: null
        userswithactive:
          type: array
          items:
            $ref: "#/components/schemas/UserWithActive"

    Interaction:
      type: object
      properties:
        id:
          type: integer
          example: 83854766
        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:55:12.853724Z"
        date_of_event:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        title:
          type: string
          example: "A title"
        comments:
          type: string
          example: "A comment"
        group_id:
          type: integer
          example: 1
        contact_id:
          type: integer
          example: 83854766
        user:
          type: object
          $ref: "#/components/schemas/UserWithoutRoleLight"
        user_id:
          type: integer
          example: 15315
        type:
          type: string
          example: "letter"
        sub_type:
          type: string
          example: "incoming"
        files:
          type: array
          items:
            allOf:
              - type: object
                properties:
                  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"
              - $ref: "#/components/schemas/Document"
        # next_step:
        #   type: string
        address:
          type: string
          example: "12 rue de la paix, 75000 Paris"
        only_super_admin:
          type: boolean
          example: false

    Note:
      type: object
      properties:
        id:
          type: integer
        data:
          type: string
        group_id:
          type: integer
        contact_id:
          type: integer
        user:
          type: object
          $ref: "#/components/schemas/UserWithoutRoleLight"
        pinned:
          type: boolean
        only_super_admin:
          type: boolean

    Import:
      type: object
      properties:
        id:
          type: string
        customer_account_id:
          type: integer
        file_name:
          type: string
        name:
          type: string
        original_file_name:
          type: string
        created_at:
          type: string
        start_read_at:
          type: integer
        country:
          type: string
        separator_char:
          type: string
        comment_char:
          type: string
        user_email:
          type: string
          format: email
        user_first_name:
          type: string
        SegmentIOUserID:
          type: string
        locale:
          type: string
        column_indexes:
          type: object
          properties:
            additional_address_fields:
              type: integer
            age:
              type: integer
            birth_city:
              type: integer
            birth_country:
              type: integer
            birth_date:
              type: integer
            building:
              type: integer
            city:
              type: integer
            country:
              type: integer
            custom_field:10113:
              type: integer
            door:
              type: integer
            email:
              type: integer
            first_name:
              type: integer
            floor:
              type: integer
            gender:
              type: integer
            house_number:
              type: integer
            last_name:
              type: integer
            married_name:
              type: integer
            mobile:
              type: integer
            note:
              type: integer
            phone:
              type: integer
            polling_station:
              type: integer
            postal_code:
              type: integer
            street:
              type: integer
        csv_settings_updated_at:
          type: string
        mapping_defined_at:
          type: string
        total_created:
          type: integer
        total_invalid_lines:
          type: integer
        total_already_exists:
          type: integer
        total_errors:
          type: integer
        on_hold_profils:
          type: integer
        resolution_strategy:
          type: string
        statuses:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              import_id:
                type: string
              label:
                type: string
              description:
                type: string
              created_at:
                type: string
        archived:
          type: boolean
    ContactCreationRequest:
      type: object
      properties:
        id:
          type: string
          example: 382cee35-748e-4ffb-8996-300271b47082
        customer_account_id:
          type: integer
          example: 1
        import_id:
          type: string
          example: 1cd82bcc-6d36-4560-b8a5-1cdff5e10749
        attrs:
          type: array
          items:
            type: object
            properties:
              str:
                type: string
              time:
                type: string
                format: date-time
              number:
                type: number
              bool:
                type: boolean
              custom_field:
                type: object
                properties:
                  FormKind:
                    type: string
                  Type:
                    type: string
                  FormID:
                    type: integer
                  Form_ref_id:
                    type: integer
                  Data:
                    type: integer
            example:
              email:
                custom_field:
                  FormKind: ''
                  Type: ''
                  FormID: 0
                  Form_ref_id: 0
                  Data: ''
                str: john.doe@example.com
                time:
                number: 0
                bool:
              first_name:
                custom_field:
                  FormKind: ''
                  Type: ''
                  FormID: 0
                  Form_ref_id: 0
                  Data: ''
                str: Johnny
                time:
                number: 0
                bool:

    Export:
      type: object
      properties:
        id:
          type: integer
          example: 1678
        user_id:
          type: integer
          example: 15315
        group_id:
          type: integer
          example: 152
        total:
          type: integer
          example: 100
        created_at:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        status:
          type: string
          example: "done"
        file_name:
          type: string
          example: "export.csv"
        notify:
          type: boolean
          example: true
        user:
          type: object
          properties:
            id:
              type: integer
            firstname:
              type: string
            lastname:
              type: string
        programmed:
          type: boolean
          example: false
        export_to_s3:
          type: boolean
          example: false
        status_s3:
          type: string
          example: "not requested"
        credential_s3:
          type: object
        name:
          type: string
          example: An export
        direct_mail_configuration:
          type: object
          properties:
            group_address_by:
              type: array
              items:
                type: string
              example:
                - postal_code
                - street
                - house_number
                - door

            one_firstname_per_person:
              type: boolean
        direct_mail:
          type: boolean

        search_request:
          type: string
          format: json
        mapping:
          type: string
          format: json
          example: '{"email":3,"firstname":1,"id":0,"mobile":5,"phone":4,"street":6,"surname":2}'
    ExportArgs:
      type: object
      properties:
        format:
          type: string
          enum:
            - csv
            - xlsx
        mapping:
          $ref: "#/components/schemas/MappingImportExport"
        name:
          type: string
          example: An export
        direct_mail_configuration:
          type: object
          properties:
            group_address_by:
              type: array
              items:
                type: string
              example:
                - postal_code
                - street
                - house_number
                - door

            one_firstname_per_person:
              type: boolean
        direct_mail:
          type: boolean
        start_at:
          type: string
          example: date
        search_request:
          type: object
          $ref: "#/components/schemas/Search"
        credential_s3_id:
          type: integer
          example: 0
        repeat_every:
          type: integer
          example: 5
        export_to_s3:
          type: boolean

    MappingImportExport:
      type: object
      properties:
        additional:
          type: integer
          example: 18
        age_category:
          type: integer
          example: 8
        birthcity:
          type: integer
          example: 7
        birthcountry:
          type: integer
          example: 6
        birthdate:
          type: integer
          example: 5
        black_list:
          type: integer
          example: 25
        building:
          type: integer
          example: 15
        city:
          type: integer
          example: 20
        coordinates:
          type: integer
          example: 22
        country:
          type: integer
          example: 21
        created_at:
          type: integer
          example: 29
        custom:
          type: integer
          example: 31
        door:
          type: integer
          example: 17
        email:
          type: integer
          example: 9
        firstname:
          type: integer
          example: 1
        floor:
          type: integer
          example: 16
        forms:
          type: integer
          example: 24
        gender:
          type: integer
          example: 4
        housenumber:
          type: integer
          example: 13
        id:
          type: integer
          example: 0
        last_change:
          type: integer
          example: 27
        last_updated_by:
          type: integer
          example: 28
        married_name:
          type: integer
          example: 3
        mobile:
          type: integer
          example: 11
        notes:
          type: integer
          example: 26
        phone:
          type: integer
          example: 10
        pollingstation:
          type: integer
          example: 12
        postal_code:
          type: integer
          example: 19
        street:
          type: integer
          example: 14
        surname:
          type: integer
          example: 2
        tags:
          type: integer
          example: 23
        updated_at:
          type: integer
          example: 30

    Polygon:
      type: array
      items:
        type: object
        properties:
          lat:
            type: number
            example: 48.869476
          lng:
            type: number
            example: 2.02458

    AdvancedSearchCondition:
      type: object
      additionalProperties: false
      properties:
        $condition:
          type: object
          required:
            - "attr"
            - "ope"
          properties:
            attr:
              type: string
              example: "surname"
              description: Attribute
            ope:
              type: string
              example: "eq"
              description: Operator
              enum:
                - eql:strictdata
                - not_eql:strictdata
                - contains
                - not_contains
                - eql
                - not_eql
                - ext
                - not_ext
                - range
                - lte
                - gte
                - start_with
                - not_start_with
            form_id:
              type: integer
              example: 4250
              description: If attr is form, the form_id is required
            form_ref_id:
              type: array
              description: If attr is form, the form_ref_id is required
              items:
                type: integer
              example: [6648]
            value:
              type: string
              description:  |-
                Value of the attr or form_ref_id if necessary (depends of the fields and the operator)
              nullable: true
              example: "Dupont"
    AdvancedSearchNode:
      type: object
      additionalProperties: false
      oneOf:
        - required: [ $all ]
        - required: [ $at_least_one ]
      properties:
        $all:
          type: array
          items:
            $ref: "#/components/schemas/AdvancedSearchCondition"
        $at_least_one:
          type: array
          items:
            $ref: "#/components/schemas/AdvancedSearchCondition"
    AdvancedSearch:
      type: object
      required: [query]
      additionalProperties: false
      properties:
        page:
          type: integer
          example: 0
        per_page:
          type: integer
          example: 50
        sort_asc:
          type: boolean
          example: true
        sort_attr:
          type: string
          example: "surname"
        query:
          type: object
          additionalProperties: false
          oneOf:
            - required: [ $all ]
            - required: [ $at_least_one ]
          properties:
            $all:
              type: array
              items:
                $ref: "#/components/schemas/AdvancedSearchNode"
            $at_least_one:
              type: array
              items:
                $ref: "#/components/schemas/AdvancedSearchNode"

    ClassicSearch:
      type: object
      properties:
        address_included:
          description: Values can be retrieve from /search/addresses
          type: array
          items:
            type: object
            properties:
              city:
                type: string
                description: Root occurence on /search/addresses response
              # count:
              #   type: integer
              #   description: Number of contacts matching the query in the city
              empty:
                type: boolean
              street:
                type: string
                description: Sub occurence on /search/addresses response
        contact_ids:
          type: array
          items:
            type: integer
        exclude_contacts:
          type: array
          items:
            type: integer
          description: Contact IDs to exclude from the results, e.g. to combine with an advanced search for a "select all except these" scenario.
        fields:
          type: array
          items:
            type: object
            properties:
              0:
                type: string
                description: "Group ID"
              1:
                type: string
              2:
                type: string
                description: Number of contacts in response
                example: "50"
              3:
                type: string
                description: Start at index
                example: "100"
              4:
                type: string
                description: Gender
                enum:
                  - m
                  - f
                  - a
                  -
              5:
                type: string
              6:
                type: string
                description: Integer corresponding to the age categories
                example: "4"
              7:
                type: string
              8:
                type: string
              9:
                type: string
                format: date-time
                description: Last visit date
              10:
                type: string
                description: Email
                enum:
                  - SET
                  - UNSET
                  -
              11:
                type: string
                description: Phone
                enum:
                  - SET
                  - UNSET
                  - ONLYMOBILE
                  -
              12:
                type: string
                description: Last visit status
              13:
                type: string
                description: Form response
        only_duplicates:
          type: boolean
        polling_station_included:
          type: array
          items:
            type: object
            properties:
              pollingstation:
                type: string
        polling_station_included_missing:
          type: boolean
        polygon:
          $ref: "#/components/schemas/Polygon"
        query:
          type: string
          description: "Query string to search by name or surname"
        tags:
          type: array
          items:
            type: string
    Search:
      anyOf:
        - $ref: "#/components/schemas/ClassicSearch"
        - properties:
            advanced_search:
              $ref: "#/components/schemas/AdvancedSearch"
            include_interactions:
              type: boolean
              example: true


    ActionArgs:
      allOf:
        - $ref: "#/components/schemas/actionMin"
        - type: object
          properties:
            search:
              type: object
            unknow_address_included:
              type: array
              items:
                type: object
            notify:
              type: boolean
    Action:
      allOf:
        - $ref: "#/components/schemas/actionMin"
        - type: object
          properties:
            created_by_detail:
              type: object
              properties:
                first_name:
                  type: string
                  example: "John"
                last_name:
                  type: string
                  example: "Doe"
                status:
                  type: string
                  example: "Disponible"
                phone:
                  type: string
                  example: "+33612345678"
                email:
                  type: string
                  format: email
                  example: "john.doe@example.org"
                avator:
                  type: string
                  example: "https://avatars.qomon.com/avatars/1.png"
            aggreg_without_location:
              type: boolean
            fields:
              type: string
              description: "Classic search fields stringified"
            polygon:
              type: string
              description: Polygon stringified
              example: "[]"
            filter:
              type: string
            advanced_search:
              type: string
              format: json
              description: "Advanced search stringified"
              example: "[]"
            polling_station_included:
              type: string
              format: json
              example: "[]"
            polling_station_excluded:
              type: string
              format: json
              example: "[]"
            polling_station_included_missing:
              type: boolean
            polling_station_excluded_missing:
              type: boolean
            address_included:
              type: string
              format: json
              example: "[]"
            address_excluded:
              type: string
              format: json
              example: "[]"
            address_included_missing:
              type: boolean
            address_excluded_missing:
              type: boolean
            not_polygon:
              type: string
              format: json
              example: "[]"
            excluded_nevada:
              type: boolean
    ActionAgreg:
        type: object
        properties:
          Action:
            $ref: "#/components/schemas/Action"
          NbVisites:
            type: integer
            example: 79
          NbContacts:
            type: integer
            example: 89
          NbVisitesDeclared:
            type: integer
            example: 79
    actionMin:
      description: |-
        Base for action and Action and ActionArgs components. Not used directly.
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
          description: Name of the action
          example: "Let's mobilize"
        type_data:
          type: string
          enum:
            - canvassing
            - calling
            - mail
            - call
            - challenge
            - static
            - sharing
            - event
            - gotvcanvassing
            - gotvcalling
            - other
        pitch:
          type: string
          description: Pitch of the action
          example: "Qomon is a great tool to mobilize people"
        status:
          type: string
          enum:
            - todo
            - finished
        group_id:
          type: integer
        Users:
          type: array
          items:
            $ref: "#/components/schemas/UserWithActive"
        Teams:
          type: array
          items:
            $ref: "#/components/schemas/Teams"
        facts:
          type: array
          items:
            type: object
        Forms:
          type: array
          items:
            type: object
        Addresses:
          type: array
          items:
            $ref: "#/components/schemas/Address"
        link:
          type: string
        goal:
          type: integer
        goal_forms:
          type: integer
        start:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        end:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        reminder_id:
          type: string
        created_by:
          type: integer
        gotv_voted_tag:
          type: string
        gotv_not_voted_tag:
          type: string
        gotv_abstention_tag:
          type: string
        public:
          type: boolean
        registration_link:
          type: string

    MetamorphArgs:
      type: object
      properties:
        contact_ids:
          type: array
          items:
            type: integer
          example: [1987, 238, 38785]
        values:
          type: array
          items:
            type: object
            properties:
              attr:
                type: string
                enum:
                  - polling_station
                  - tags
                  - status
                  - city
                  - postal_code
                  - black_list
              value:
                type: string
    Metamorph:
      allOf:
        - type: object
          properties:
            id:
              type: integer
              example: 18798
            CreatedAt:
              type: string
              format: date-time
              example: "2022-10-13T15:50:34.643724Z"
            UpdatedAt:
              type: string
              format: date-time
              example: "2022-10-13T15:50:34.643724Z"
            user_id:
              type: integer
              example: 14733
            group_id:
              type: integer
              example: 452
            status:
              type: string
              enum:
                - requested
                - done
                - error
            values:
              type: array
              items:
                type: object
                properties:
                  id:
                    type: integer
                    example: 17476
        - $ref: "#/components/schemas/MetamorphArgs"

    MassiveManipulationArgs:
      type: object
      properties:
        search_request:
          $ref: "#/components/schemas/Search"
    MassiveManipulation:
      type: object
      properties:
        id:
          type: integer
          example: 18798
        created_at:
          type: string
          format: date-time
          example: "2022-10-13T15:50:34.643724Z"
        user_id:
          type: integer
          example: 1473
        group_id:
          type: integer
          example: 452
        status:
          type: string
          enum:
            - requested
            - wip_deleting
            - done
            - error
        search_request:
          type: string
          format: json
          description: "Search request stringified"
        total:
          type: integer
          example: 50

    TransferArgs:
      type: object
      required: [target_group_id]
      properties:
        search:
          $ref: "#/components/schemas/Search"
        target_group_id:
          type: integer
          description: Must be one of the groups currently selected by the requesting user.
          example: 1888
    TransferJob:
      type: object
      properties:
        id:
          type: integer
          example: 254
        groupIds:
          type: array
          items:
            type: integer
          description: Groups currently selected by the requesting user when the job was created.
          example: [1888, 2636]
        CreatedAt:
          type: string
          format: date-time
          example: "2026-07-29T16:00:00Z"
        userId:
          type: integer
          example: 14733
        contacts:
          type: array
          items:
            type: integer
          description: Explicit contact IDs from search.contact_ids, if provided.
          example: [345678, 234567]
        search:
          type: string
          format: json
          description: "The submitted search, stringified"
        completedCount:
          type: integer
          description: Number of contacts transferred so far.
          example: 0

    List:
      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

    Sms:
      type: object
      properties:
        id:
          type: integer
        created:
          type: string
          format: date-time
        from:
          type: string
        to:
          type: string
        message:
          type: string
        group_id:
          type: integer
        error:
          type: string
        status:
          type: string
        messageuuid:
          type: string
        campainid:
          type: string
        number_of_credit_needed:
          type: integer
        country:
          type: string
        type:
          type: string
        network_provider_code:
          type: string
        received_optin_or_optout:
          type: boolean
        message_id_for_consent_url:
          type: string

    Email:
      type: object
      properties:
        id:
          type: integer
        created:
          type: string
          format: date-time
        sender:
          type: string
        sender_name:
          type: string
        cc:
          type: string
        subject:
          type: string
        object:
          type: string
        receiver:
          type: string
        surname:
          type: string
        firstname:
          type: string
        gender:
          type: string
        group_id:
          type: integer
        type:
          type: string
        contacts:
          type: array
        imap_message_id:
          type: string
        email_engine_id:
          type: string
        unseen:
          type: boolean
        attachments:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              contentType:
                type: string
              embedded:
                type: boolean
              inline:
                type: boolean
              contentId:
                type: string
              filename:
                type: string
              rawdata:
                type: string
                format: binary
              contentDisposition:
                type: string
        reference:
          type: object
          properties:
            message:
              type: string
            inline:
              type: boolean
            action:
              type: string
        thread_id:
          type: string
        emails:
          type: array

    History:
      type: array
      items:
        type: object
        allOf:
          - type: object
            properties:
              date_for_ordering:
                type: string
                format: date-time
                example: "2022-10-13T15:50:34.643724Z"
          # - $ref: "#/components/schemas/FormData"
          # - type: object
          #   properties:
          #     formadatas:
          #       type: array
          #       items:
          #         $ref: "#/components/schemas/FormData"
          - oneOf:
            - type: object
              properties:
                fact:
                  type: object
                  properties:
                    status:
                      type: string
                      enum:
                        - todo
                        - done
                    type:
                      type: string
                      example: Event of the year
            - type: object
              properties:
                email:
                  $ref: "#/components/schemas/Email"
            - type: object
              properties:
                sms:
                  $ref: "#/components/schemas/Sms"
            - type: object
              properties:
                note:
                  $ref: "#/components/schemas/Note"
            - type: object
              properties:
                import:
                  type: object
                  properties:
                    ImportID:
                      type: string
                    CreatedAt:
                      type: string
                      format: date-time
                    Name:
                      type: string
                    UserName:
                      type: string
            - type: object
              properties:
                interaction:
                  $ref: "#/components/schemas/Interaction"
            - type: object
              properties:
                petition:
                  type: object
                  properties:
                    contact_id:
                      type: string
                    base_id:
                      type: string
                    sites:
                      type: object
                    contact:
                      type: object
                    signed_at:
                      type: string
                      format: date-time
                    type:
                      type: string
                    title:
                      type: string
            - type: object
              properties:
                online_form:
                  type: object
                  properties:
                    contact_id:
                      type: string
                    base_id:
                      type: string
                    sites:
                      type: object
                    contact:
                      type: object
                    signed_at:
                      type: string
                      format: date-time
                    type:
                      type: string
                    title:
                      type: string

security:
  - apiKey: []
