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

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


tags:
  - name: Filters

paths:
  /filters:
    get:
      tags:
        - Filters
      summary: List saved filters
      description: Returns all saved filters for the selected group.
      security:
        - apiKey: []
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/SavedFilter'
    post:
      tags:
        - Filters
      summary: Create a saved filter
      description: Creates a saved filter. The group and user are inferred from the authenticated context.
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SavedFilterCreateRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: '#/components/schemas/SavedFilter'
    patch:
      tags:
        - Filters
      summary: Update a saved filter
      description: Updates an existing saved filter.
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SavedFilterUpdateRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    $ref: '#/components/schemas/SavedFilter'
    delete:
      tags:
        - Filters
      summary: Delete a saved filter
      description: Deletes a saved filter by ID.
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SavedFilterDeleteRequest'
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    nullable: true
                    type: object

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer

  schemas:
    Point:
      type: object
      required: [lat, lng]
      properties:
        lat:
          type: number
          format: double
          example: 49.252079999
        lng:
          type: number
          format: double
          example: 4.043889534

    SavedFilter:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 123
        group_id:
          type: integer
          format: int64
          example: 1283
        title:
          type: string
          example: My polygon filter
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        deleted_at:
          nullable: true
        user_id:
          type: integer
          format: int64
        payload:
          type: string
          description: Advanced search query serialized as a JSON string.
          example: '{"$all":[{"$at_least_one":[{"$condition":{"attr":"mail","ope":"start_with","value":"hugo+123"}},{"$condition":{"attr":"mail","ope":"start_with","value":"hugo+124"}}]}]}'
        polygons:
          type: array
          description: Polygon coordinates stored as an array of points.
          items:
            $ref: '#/components/schemas/Point'
        is_favorite:
          type: boolean
          default: false
        is_segment:
          type: boolean
          default: false

    SavedFilterCreateRequest:
      type: object
      required: [title, payload]
      properties:
        title:
          type: string
          example: My polygon filter
        payload:
          type: string
          description: Advanced search query serialized as a JSON string.
          example: '{"$all":[{"$at_least_one":[{"$condition":{"attr":"mail","ope":"start_with","value":"hugo+123"}},{"$condition":{"attr":"mail","ope":"start_with","value":"hugo+124"}}]}]}'
        polygons:
          type: array
          description: Polygon coordinates stored as an array of points.
          items:
            $ref: '#/components/schemas/Point'
        is_favorite:
          type: boolean
          default: false
        is_segment:
          type: boolean
          default: false

    SavedFilterUpdateRequest:
      allOf:
        - type: object
          required: [id]
          properties:
            id:
              type: integer
              format: int64
              example: 123
        - $ref: '#/components/schemas/SavedFilterCreateRequest'

    SavedFilterDeleteRequest:
      type: object
      required: [id]
      properties:
        id:
          type: integer
          format: int64
          example: 123
        is_segment:
          type: boolean
          description: Indicates whether the filter is a segment to trigger related cleanup.

security:
  - apiKey: []