BaseResponseSchema:
  description: The response schema for a successful operation
  type: object
  properties:
    version:
      type: string
    success:
      type: boolean
    data:
      type: object
  required:
    - version
    - success
    - data
  example:
    version: '1'
    success: true
    data: {}

BasePaginatedResponseSchema:
  description: The response schema for a successful operation
  allOf:
  - $ref: '#/BaseResponseSchema'
  - type: object
    properties:
      data:
        type: object
        allOf:
          - $ref: '#/PaginatedListSchema'
    required:
      - data
    example:
      data:
        object: list
        data:
        pagination:
          start_after: null
          start_by: id
          per_page: 10
          count: 5
          is_first_page: true
          is_last_page: true

ErrorSchema:
  description: The object schema for an error
  type: object
  properties:
    object:
      type: string
    code:
      type: string
    description:
      type: string
    messages:
      type: object
  required:
    - object
    - code
    - description
    - messages
  example:
    object: error
    code: server:internal_server_error
    description: Something went wrong on the server
    messages: {error_key: error_reason}

UnpaginatedListSchema:
  description: The object schema for an unpaginated list
  type: object
  properties:
    object:
      type: string
    data:
      type: array
      items:
        type: object
  required:
    - object
    - data
  example:
    object: list
    data: []

PaginatedListSchema:
  description: The object schema for a paginated list
  type: object
  properties:
    object:
      type: string
    data:
      type: array
      items:
        type: object
    pagination:
      type: object
      items:
        type: object
      properties:
        start_after: {}
        start_by:
          type: string
        per_page:
          type: integer
        count:
          type: integer
        is_first_page:
          type: boolean
        is_last_page:
          type: boolean
      required:
        - start_after
        - start_by
        - per_page
        - count
        - is_first_page
        - is_last_page
  required:
    - object
    - data
    - pagination

AdvancedFilteringSchema:
  type: array
  items:
    type: object
    properties:
      field:
        type: string
      comparator:
        type: string
      value:
        type: string
    required:
      - field
      - comparator
      - value

PaginatedRequestBodySchema:
  properties:
    start_after: {}
    start_by:
      type: string
    per_page:
      type: integer
      minimum: 1
    search_term:
      type: string
    match_all:
      $ref: '#/AdvancedFilteringSchema'
    match_any:
      $ref: '#/AdvancedFilteringSchema'
    sort_by:
      type: string
    sort_dir:
      type: string
      enum: [asc, desc]
  example:
    start_after: null
    start_by: id
    per_page: 10
    match_all: []
    match_any: []
    sort_by: created_at
    sort_dir: desc

FilteredRequestBodySchema:
  properties:
    search_term:
      type: string
    match_all:
      $ref: '#/AdvancedFilteringSchema'
    match_any:
      $ref: '#/AdvancedFilteringSchema'
    sort_by:
      type: string
    sort_dir:
      type: string
      enum: [asc, desc]
  example:
    match_all: []
    match_any: []
    sort_by: created_at
    sort_dir: desc
