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: Tags
    description: Setup tags
  - name: Privacy policy
  - name: Nation builder
    description: Nation builder integration

paths:
  /billing/subscription:
    get:
      tags:
        - Billing
      summary: Get current subscription
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: 'success'
                  data:
                    type: object
                    $ref: '#/components/schemas/BillingSubscription'

  /tags:
    get:
      tags:
        - Tags
      summary: Get tags
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Tag'
    patch:
      tags:
        - Tags
      summary: Update a tag
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    old_tag:
                      $ref: '#/components/schemas/Tag'
                    tag:
                      description: New values
                      type: object
                      properties:
                        name:
                          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        appearance_count:
                          type: integer
                        color:
                          type: string
    post:
      tags:
        - Tags
      summary: Create a tag
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                data:
                  type: object
                  properties:
                    tag:
                      type: object
                      properties:
                        name:
                          type: string
                        color:
                          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      tag:
                        $ref: '#/components/schemas/Tag'
    delete:
      tags:
        - Tags
      summary: Delete a tag
      description: Only the name of the tag is required
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    tag:
                      $ref: '#/components/schemas/Tag'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  data:
                    type: object
                    properties:
                      tag:
                        $ref: '#/components/schemas/Tag'

  /privacy_policy:
    get:
      tags:
        - Privacy policy
      summary: Get privacy policy
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: 'success'
                  data:
                    type: object
                    properties:
                      privacy_policy:
                        $ref: '#/components/schemas/PrivacyPolicy'
    post:
      tags:
        - Privacy policy
      summary: Update privacy policy
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    privacy_policy:
                      $ref: '#/components/schemas/PrivacyPolicy'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: 'success'
                  data:
                    type: object
                    properties:
                      privacy_policy:
                        $ref: '#/components/schemas/PrivacyPolicy'

  /nationbuilder/connect/{nation}:
    get:
      tags:
        - Nation builder
      summary: Get url for nation builder connection
      parameters:
        - name: nation
          in: path
          required: true
          description: Nation name
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: success
                  data:
                    type: string
                    format: uri
                    example: 'https://quorum.nationbuilder.com/oauth/authorize?response_type=code&client_id=Wm8x8sWRqPL98ukMLGeH5tM8z7KWNO4QXq30l_y_7kE&redirect_uri=https://qomon.app/nationbuilder/nb-auth-code'
    delete:
      tags:
        - Nation builder
      summary: Disconnect from nation builder
      parameters:
        - name: nation
          in: path
          required: true
          description: Nation name
          schema:
            type: string
      responses:
        '200':
          description: Successfully deleted

components:
  schemas:
    BillingSubscription:
      type: object
      properties:
        package_name:
          type: string
          example: 'premium'
        limit:
          type: integer
          example: 250000
        suspended:
          type: boolean
          example: false
        billing_portal_url:
          type: string
        created_at:
          type: string
          format: date-time
          example: '2020-01-01T00:00:00Z'
        interval:
          type: string
          example: 'month'
        next_invoice:
          type: string
          format: date-time
          example: '2020-01-01T00:00:00Z'

    EmailSubscription:
      type: object
      properties:
        quantity:
          type: integer
          example: 300
        interval:
          type: string
          enum:
            - month
            - year
        next_invoice:
          type: string
          format: datetime
          nullable: true
          example: '2020-01-01T00:00:00Z'

    Tag:
      type: object
      properties:
        name:
          type: string
        appearance_count:
          type: integer
        color:
          type: string

    PrivacyPolicy:
      type: object
      properties:
        group_id:
          type: integer
          example: 432
        url:
          type: string
          example: 'https://qomon.com/data-and-security'
