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: Petitions
    description: Create, update, delete, publish petitions
  - name: Online forms
    description: Create, update, delete, publish online forms
  - name: Flux RSS

paths:
  /petitions:
    get:
      tags:
        - Petitions
      summary: List petitions
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      petitions:
                        type: array
                        items:
                          $ref: "#/components/schemas/Petition"
    post:
      tags:
        - Petitions
      summary: Create a petition
      description: ids are ignored
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    petition:
                      $ref: "#/components/schemas/PetitionEdition"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      petition:
                        $ref: "#/components/schemas/PetitionEdition"
  /public-petitions/{globalCause}:
    get:
      tags:
        - Petitions
      parameters:
        - $ref: "#/components/parameters/globalCause"
      summary: Get petitions by global cause and subdivision
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      Petitions:
                        type: array
                        items:
                          $ref: "#/components/schemas/Petition"
  /public-petitions/{globalCause}/{subdivision}:
    get:
      tags:
        - Petitions
      parameters:
        - $ref: "#/components/parameters/globalCause"
        - $ref: "#/components/parameters/subdivision"
      summary: Get petitions by global cause and subdivision
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      Petitions:
                        type: array
                        items:
                          $ref: "#/components/schemas/Petition"
  /petitions/{idPetition}:
    get:
      tags:
        - Petitions
      parameters:
        - $ref: "#/components/parameters/idPetition"
      summary: Get detail of a petition
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      petition:
                        $ref: "#/components/schemas/PetitionEdition"
    patch:
      tags:
        - Petitions
      summary: Update a petition (state, style, etc)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    petition:
                      $ref: "#/components/schemas/PetitionEdition"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      petition:
                        $ref: "#/components/schemas/PetitionEdition"
  /petitions/{idPetition}/publish:
    patch:
      tags:
        - Petitions
      parameters:
        - $ref: "#/components/parameters/idPetition"
        - $ref: "#/components/parameters/statePetition"
      summary: Publish a petition
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    petition:
                      $ref: "#/components/schemas/PetitionEdition"
      responses:
        "200":
          description: OK
  /categories:
    get:
      tags:
        - Petitions
      summary: List available categories
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "success"
                  data:
                    type: object
                    properties:
                      categories:
                        type: array
                        items:
                          type: object
                          properties:
                            type:
                              type: string
                        example:
                          $ref: "#/components/examples/categoriesExample"

  /online-forms:
    get:
      tags:
       - Online forms
      summary: List online forms
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      online_forms:
                        type: array
                        items:
                          $ref: "#/components/schemas/OnlineForm"
    post:
      tags:
       - Online forms
      summary: Create an online form
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      online_form:
                        $ref: "#/components/schemas/OnlineFormCreation"
  /online-forms/{onlineformBaseId}:
    get:
      tags:
       - Online forms
      summary: Get an online form
      parameters:
        - $ref: "#/components/parameters/onlineformBaseId"
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      online_form:
                        $ref: "#/components/schemas/OnlineFormEdition"
    patch:
      tags:
       - Online forms
      summary: Edit an online form
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    online_form:
                      $ref: "#/components/schemas/OnlineFormEdition"
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      online_form:
                        $ref: "#/components/schemas/OnlineFormEdition"
  /online-forms/{onlineformBaseId}/publish:
    patch:
      tags:
       - Online forms
      summary: Publish an online form
      parameters:
        - $ref: "#/components/parameters/onlineformBaseId"
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      online_form:
                        $ref: "#/components/schemas/OnlineFormEdition"


  /public-rss/{globalCause}:
    get:
      tags:
        - Flux RSS
      summary: Get RSS feed for a global cause
      parameters:
        - $ref: "#/components/parameters/globalCause"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        url:
                          type: string

  /public-rss/{globalCause}/{subdivision}:
    get:
      tags:
        - Flux RSS
      summary: Get RSS feed for a global cause and subdivision
      parameters:
        - $ref: "#/components/parameters/globalCause"
        - $ref: "#/components/parameters/subdivision"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        url:
                          type: string


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

  parameters:
    idPetition:
      name: idPetition
      in: path
      required: true
      schema:
        type: string
        format: uuid
    globalCause:
      name: globalCause
      in: path
      required: true
      schema:
        type: string
        format: uuid
    subdivision:
      name: subdivision
      in: path
      required: true
      schema:
        type: string
        format: uuid
    statePetition:
      name: state
      in: path
      required: true
      schema:
        type: string
        enum:
          - draft
          - published
          - closed
          - archived
    onlineformBaseId:
      name: onlineformBaseId
      in: path
      required: true
      schema:
        type: string
        format: uuid

  examples:
    categoriesExample:
      value:
      - type: agriculture
      - type: animals
      - type: arts
      - type: culture
      - type: disability
      - type: ecology
      - type: education
      - type: energy
      - type: environnement
      - type: equality
      - type: family
      - type: global-warming
      - type: health
      - type: human-rights
      - type: immigration
      - type: justice
      - type: lgbt
      - type: medias
      - type: security
      - type: social
      - type: sports
      - type: work


  schemas:
    siteBase:
      type: object
      properties:
        slug:
          type: string
        author:
          type: string
        title:
          type: string
        language:
          type: string
        state:
          type: string
        indexing:
          type: boolean
        form_state:
          type: string
        cover_img:
          type: object
          properties:
            url:
              type: string
            cover_img_x:
              type: string
              format: nullable
            cover_img_y:
              type: string
              format: nullable
            background_size_ratio:
              type: string
              format: nullable

    Petition:
      allOf:
        - type: object
          properties:
            id:
              type: string
              description: Omit at creation
            petition_id:
              type: string
            CreatedAt:
              type: string
              format: date-time
              example: "2020-10-01T00:00:00Z"
              description: Omit at creation
            UpdatedAt:
              type: string
              format: date-time
              example: "2020-10-01T00:00:00Z"
              description: Omit at creation
            DeletedAt:
              type: string
              format: date-time
              example: null
              description: Omit at creation
            end_date:
              type: string
              format: date-time
            preset_amount:
              type: integer
            target_amount:
              type: integer
            archived:
              type: boolean
              description: Omit at creation
            amount:
              type: integer
            categories:
              type: array
              items:
                type: object
                properties:
                  type:
                    type: string
              description: List of categories. All categories are available at /categories.
        - $ref: "#/components/schemas/siteBase"
    PetitionEdition:
      allOf:
        - $ref: "#/components/schemas/Petition"
        - type: object
          properties:
            body:
              type: array
              items:
                type: object
            auto_insert_refvalues:
              $ref: "#/components/schemas/auto_insert_refvalues"
            favicon:
              type: string
            titleExtension:
              type: string
            fields:
              $ref: "#/components/schemas/fields"
            web_integration:
              $ref: "#/components/schemas/web_integration"
            tags:
              $ref: "#/components/schemas/Tags"
            target_person:
              type: string
            colors:
              $ref: "#/components/schemas/colors"
            share:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                  show:
                    type: boolean
                  text:
                    type: string
                  body:
                    type: string
                  subject:
                    type: string
            legal:
              $ref: "#/components/schemas/site_legals"
            isTargetPerson:
              type: boolean
            isEndDate:
              type: boolean

    OnlineForm:
      allOf:
        - type: object
          properties:
            id:
              type: string
            base_id:
              type: string
            CreatedAt:
              type: string
            UpdatedAt:
              type: string
            archived:
              type: boolean
        - $ref: "#/components/schemas/siteBase"
    onlineFormBase:
      type: object
      properties:
        type:
          type: string
        # body:
        sign_button:
          type: string
        fields:
          $ref: "#/components/schemas/fields"
        legal:
          $ref: "#/components/schemas/site_legals"
        auto_insert_refvalues:
          $ref: "#/components/schemas/auto_insert_refvalues"
        tags:
          $ref: "#/components/schemas/Tags"
        colors:
          $ref: "#/components/schemas/colors"
        # share:
        web_integration:
          $ref: "#/components/schemas/web_integration"
        confirmation_page:
          $ref: "#/components/schemas/confirmation_page"
        redirect_url:
          type: string
    OnlineFormCreation:
      allOf:
        - $ref: "#/components/schemas/siteBase"
        - $ref: "#/components/schemas/onlineFormBase"
        - type: object
          properties:
            template:
              type: string
            description:
              type: string

    OnlineFormEdition:
      allOf:
        - $ref: "#/components/schemas/OnlineForm"
        - type: object
          properties:
            group_id:
              type: integer
            user_id:
              type: integer
        - $ref: "#/components/schemas/onlineFormBase"

    Tags:
      type: array
      items:
        type: object
        properties:
          name:
            type: string

    fields:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
            description: Omit at creation
          sites_id:
            type: string
            description: Omit at creation
          age_category:
            type: array
            items:
              type: object
            example: null
            description: if type is Age
          custom_id:
            type: integer
          default:
            type: string
            description: Default value
          description:
            type: string
          field_type:
            type: string
            enum:
              - date
              - text
              - checkbox
              - radio
              - numeric
            nullable: true
            description: Default field_type. Can't be changed
          hidden:
            type: boolean
          label:
            type: string
          mandatory:
            type: boolean
          order:
            type: integer
          placeholder:
            type: string
          type:
            type: string
            example: firstname
          variant:
            type: string
            enum:
              - select
              - multiselect
              - radio
              - checkbox
            nullable: true
            description: Override field_type

    confirmation_page:
      type: object
      properties:
        id:
          type: integer
          description: Omit at creation
        sites_id:
          type: string
          description: Omit at creation
        title:
          type: string
        body:
          type: string

    web_integration:
      type: object
      properties:
        header:
          type: boolean
        width:
          type: object
          properties:
            value:
              type: integer
            type:
              type: string
        height:
          type: object
          properties:
            value:
              type: integer
            type:
              type: string
        transparency:
          type: integer

    auto_insert_refvalues:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
          CreatedAt:
            type: string
          UpdatedAt:
            type: string
          form_id:
            type: integer
          label:
            type: string
          value:
            type: string
          min:
            type: integer
          auto_send:
            type: string
          auto_send_sms:
            type: string
          color:
            type: string
    colors:
      type: array
      items:
        type: object
        properties:
          name:
            type: string
          value:
            type: string
    site_legals:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
            description: Omit at creation
          sites_id:
            type: string
            description: Omit at creation
          type:
            type: string
            enum:
              - privacy_policy
              - "yes"
              - consent_email
              - consent_mobile
          label:
            type: string
          mandatory:
            type: boolean
          hidden:
            type: boolean
          order:
            type: integer
