openapi: 3.0.0
info:
  version: "0.0"
  title: Qomon
  description: |-
    This is fact'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: Facts
    description: Everything about facts. A fact is a contact in an action with a status and a list of form data.

paths:
  /aggregfacts:
    post:
      tags:
        - Facts
      summary: Get facts by action id
      description: |-
        List all facts of an action. Facts are grouped by city, street, house number.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    fields:
                      type: object
                      properties:
                        0:
                          type: string
                          format: integer
                          description: action id, user that request must member of the action
                        1:
                          type: string
                          enum:
                            - aggregswithoutcontacts
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      FactsAggreg:
                        type: object
                        properties:
                          cnt:
                            type: integer
                            description: Number of contacts in the action
                          st:
                            type: string
                            description: Status of the action
                          vis:
                            type: integer
                            description: Number of contacts already seen in the action
                          cities:
                            type: array
                            items:
                              type: object
                              properties:
                                city:
                                  type: string
                                  example: Paris
                                cnt:
                                  type: integer
                                  description: Number of contacts in this city
                                st:
                                  type: string
                                  description: Status of the city
                                vis:
                                  type: integer
                                  description: Number of contacts already seen in this city
                                ss:
                                  type: array
                                  description: List of streets in this city
                                  items:
                                    type: object
                                    properties:
                                      s:
                                        type: string
                                        description: Street name
                                        example: Rue de la Paix
                                      cnt:
                                        type: integer
                                        description: Number of contacts in this street
                                      st:
                                        type: string
                                        description: Status of the street
                                        example: done
                                      vis:
                                        type: integer
                                        description: Number of contacts already seen in this street
                                      hns:
                                        type: array
                                        description: List of house number in this street
                                        items:
                                          type: object
                                          properties:
                                            hn:
                                              type: string
                                              description: House number
                                              example: 215
                                            pol:
                                              type: string
                                              description: Polling station
                                            cnt:
                                              type: integer
                                              description: Number of contacts at this house number
                                            st:
                                              type: string
                                              description: Status of the house number
                                              example: done
                                            vis:
                                              type: integer
                                              description: Number of contacts already seen at this house number
                                            fts:
                                              type: array
                                              description: List of facts at this house number
                                              items:
                                                type: object
                                                properties:
                                                  ID:
                                                    type: integer
                                                  st:
                                                    type: string
                                                    description: Status of the fact
                                                  c:
                                                    type: array
                                                    description: Contacts that have this fact
                                                    items:
                                                      type: object
                                                      properties:
                                                        id:
                                                          type: integer
                                                        fn:
                                                          type: string
                                                          description: First name
                                                          example: Paul
                                                        sn:
                                                          type: string
                                                          description: Surname
                                                          example: Dupont
                                                        gd:
                                                          type: string
                                                          description: Gender
                                                          example: M
                                                        bd:
                                                          type: string
                                                          format: date-time
                                                          description: Birth date
                                                        lc:
                                                          type: string
                                                          format: date-time
                                                          description: Last change date
                                                        fd:
                                                          type: array
                                                          description: Form data
                                                          items:
                                                            $ref: "#/components/schemas/FormData"
                                      fts:
                                        type: array
                                        items:
                                          type: object
                                          properties:
                                            ID:
                                              type: integer
                                            st:
                                              type: string
                                            c:
                                              type: array
                                              items:
                                                type: object
                                                properties:
                                                  id:
                                                    type: integer
                                                  fn:
                                                    type: string
                                                    description: First name
                                                  sn:
                                                    type: string
                                                    description: Surname
                                                  gd:
                                                    type: string
                                                    description: gender
                                                  bd:
                                                    type: string
                                                    format: date-time
                                                    description: Birth date
                                                  ac:
                                                    type: integer
                                                    description: age category
                                                  lc:
                                                    type: string
                                                    description: Last change date
                                                  fd:
                                                    type: array
                                                    description: Form data
                                                    items:
                                                      $ref: "#/components/schemas/FormData"
  /facts:
    post:
      tags:
        - Facts
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ActionID:
                  type: integer
                  description: ID of the action
                fact:
                  $ref: "#/components/schemas/Fact"
              example:
                ActionID: 3938
                fact:
                  Contacts:
                  - address:
                      city: auckland
                    custom_fields: []
                    formdatas:
                    - data: present
                      date: '2023-12-05T09:16:12.362Z'
                      form_id: 4645
                      form_ref_id: 7985
                      group_id: 211
                    - data: 'yes'
                      date: '2023-12-05T09:16:13.794Z'
                      form_id: 4646
                      form_ref_id: 7996
                      group_id: 211
                    group_id: 211
                  status: done
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      fact:
                        $ref: "#/components/schemas/Fact"
                    example:
                      fact:
                        ID: 12598737
                        group_id: 1
                        status: done
                        user_id: 3714
                        Contacts:
                        - id: 3723569
                          CreatedAt: '2023-12-06T13:51:53.440191Z'
                          UpdatedAt: '2023-12-06T13:51:53.440191Z'
                          address:
                            id: 4140750
                            city: auckland
                            country: FRA
                            score: 0.314133
                            latitude: '44.222454'
                            longitude: '5.428243'
                            location: 44.222454,5.428243
                          action_ids:
                          lastchange: '2023-12-05T09:16:13.794Z'
                          group_id: 1
                          user_id: 3714
                          formdatas:
                          - id: 1178612
                            data: present
                            date: '2023-12-05T09:16:12.362Z'
                            group_id: 1
                            contact_id: 3723569
                            form_id: 4645
                            form_ref_id: 7985
                          - id: 1178613
                            data: 'yes'
                            date: '2023-12-05T09:16:13.794Z'
                            group_id: 1
                            contact_id: 3723569
                            form_id: 4646
                            form_ref_id: 7996
    patch:
      tags:
        - Facts
      summary: Update contact of a fact
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ActionID:
                  type: integer
                fact:
                  $ref: "#/components/schemas/Fact"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      fact:
                        $ref: "#/components/schemas/Fact"
  /facts/all:
    patch:
      tags:
        - Facts
      summary: Mark adress as done
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                level:
                  type: string
                  enum:
                    - street
                    - hn
                    - building
                    - floor
                level_value_floor:
                  type: string
                level_value_building:
                  type: string
                level_value_hn:
                  type: string
                level_value_street:
                  type: string
                level_value_city:
                  type: string
                search:
                  $ref: "#/components/schemas/Search"
                fact_ids:
                  type: array
                  items:
                    type: integer
                status:
                  type: string
                  enum:
                    - done
                    - todo
            examples:
              Mark street as done:
                value:
                  level: street
                  level_value_city: paris
                  level_value_street: boulevard raspail
                  search:
                    Search:
                      fields: ['4004', aggregswithoutcontacts]
                  status: done
              Mark the building as done:
                value:
                  level: hn
                  level_value_city: paris
                  level_value_hn: '57'
                  level_value_street: rue de rennes
                  search:
                    Search:
                      fields: ['4004', 'aggregswithoutcontacts']
                  status: done

      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      fact:
                        nullable: true
                        example: null
  /facts_by_contact_id/{contactId}:
    get:
      tags:
        - Facts
      parameters:
        - $ref: "#/components/parameters/contactId"
      description: Get facts by contact id
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      fact:
                        $ref: "#/components/schemas/Fact"
  /facts/{factId}:
    get:
      tags:
        - Facts
      parameters:
        - $ref: "#/components/parameters/factId"
      description: Get a fact by id
      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      fact:
                        $ref: "#/components/schemas/Fact"

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
  parameters:
    factId:
      name: factId
      in: path
      description: ID of the fact to fetch
      required: true
      schema:
        type: integer
        example: 45239
    contactId:
      name: contactId
      in: path
      description: ID of a contact
      required: true
      schema:
        type: integer
        example: 83854766
  schemas:
    Fact:
      type: object
      properties:
        ID:
          type: integer
        CreatedAt:
          type: string
          format: date-time
        UpdatedAt:
          type: string
          format: date-time
        DeletedAt:
          type: string
          format: date-time
        group_id:
          type: integer
        type:
          type: string
        status:
          type: string
        declared_status:
          type: string
        user_id:
          type: integer
        Contacts:
          type: array
          items:
            type: object
            properties:
                id:
                  type: integer
                CreatedAt:
                  type: string
                  format: date-time
                UpdatedAt:
                  type: string
                  format: date-time
                firstname:
                  type: string
                surname:
                  type: string
                gender:
                  type: string
                birthdate:
                  type: string
                  format: date-time
                action_ids:
                  type: array
                  format: nullable
                  items:
                    type: integer
                group_id:
                  type: integer
                address:
                  type: object
                  properties:
                    id:
                      type: integer
                    housenumber:
                      type: string
                    street:
                      type: string
                    postalcode:
                      type: string
                    city:
                      type: string
                    country:
                      type: string
                    pollingstation:
                      type: string
                    score:
                      type: number
                    latitude:
                      type: string
                      format: float
                    longitude:
                      type: string
                      format: float
                    location:
                      type: string
                formdatas:
                  type: array
                  items:
                    $ref: "#/components/schemas/FormData"
        addresses:
          type: array
          items:
            $ref: "#/components/schemas/Address"
          example: []
        formdatas:
          type: array
          items:
            $ref: "#/components/schemas/FormData"
          example: []
