sources:
  - name: GreenInvoice
    handler:
      jsonSchema:
        endpoint: 'https://api.greeninvoice.co.il/api/v1'
        operationHeaders:
          Authorization: Bearer {context.authToken}
          Content-Type: application/json
        operations:
          # documents #

          - type: Query
            field: getDocument
            path: /documents/{args.id}
            method: GET
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getDocumentResponse

          - type: Query
            field: searchDocuments
            path: /documents/search
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/searchDocumentsRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/searchDocumentsResponse

          - type: Query
            field: previewDocument
            path: /documents/preview
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/previewDocumentRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/previewDocumentResponse

          - type: Query
            field: getLinkedDocuments
            path: /documents/{args.id}/linked
            method: GET
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getLinkedDocumentsResponse

          - type: Query
            field: getDocumentsDownloadLinks
            path: /documents/{args.id}/download/links
            method: GET
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getDocumentsDownloadLinksResponse

          - type: Mutation
            field: addDocument
            path: /documents
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/addDocumentRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/addDocumentResponse

          - type: Mutation
            field: closeDocument
            path: /documents/{args.id}/close
            method: POST
            argTypeMap:
              id:
                type: string
                nullable: false
            responseByStatusCode:
              200:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/closeDocumentResponse

          # expenses #

          - type: Query
            field: getExpense
            path: /expenses/{args.id}
            method: GET
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getExpenseResponse

          - type: Query
            field: searchExpenses
            path: /expenses/search
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/searchExpensesRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/searchExpensesResponse

          - type: Mutation
            field: addExpense
            path: /expenses
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/addExpenseRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/addExpenseResponse

          - type: Mutation
            field: updateExpense
            path: /expenses/{args.id}
            method: PUT
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/updateExpenseRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/updateExpenseResponse

          # expense drafts #

          - type: Query
            field: searchExpenseDrafts
            path: /expenses/drafts/search
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/searchExpenseDraftsRequest
            responseByStatusCode:
              200:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/searchExpenseDraftsResponse
              201:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/searchExpenseDraftsResponse
              404:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/generalErrorResponse

          - type: Mutation
            field: addExpenseDraftByFile
            path: /expenses/file
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/addExpenseDraftByFileRequest
            responseByStatusCode:
              200:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/addExpenseDraftByFileResponse
              201:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/addExpenseDraftByFileResponse
              400:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/generalErrorResponse
              404:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/generalErrorResponse
              405:
                responseSchema: ../json-schemas/greenInvoice.json#/$defs/generalErrorResponse

          # clients #

          - type: Query
            field: getClient
            path: /clients/{args.id}
            method: GET
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getClientResponse

          - type: Mutation
            field: addClient
            path: /clients
            method: POST
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/addClientRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/addClientResponse

          - type: Mutation
            field: updateClient
            path: /clients/{args.id}
            method: PUT
            argTypeMap:
              id:
                type: string
                nullable: false
            requestSchema: ../json-schemas/greenInvoice.json#/$defs/updateClientRequest
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/updateClientResponse

          - type: Mutation
            field: deleteClient
            path: /clients/{args.id}
            method: DELETE
            argTypeMap:
              id:
                type: string
                nullable: false
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/deleteClientResponse

  - name: GreenInvoiceNew
    handler:
      jsonSchema:
        endpoint: 'https://apigw.greeninvoice.co.il'
        operationHeaders:
          Authorization: Bearer {context.authToken}
          Content-Type: application/json
        operations:
          - type: Query
            field: getFileUploadUrl
            path: /file-upload/v1/url
            method: GET
            argTypeMap:
              context:
                type: string
              data:
                type: object
                properties:
                  source:
                    type: integer
                  id:
                    type: string
                  state:
                    type: string
                required:
                  - source
            queryStringOptions:
              jsonStringify: true
            queryParamArgMap:
              context: context
              data: data
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getFileUploadUrlResponse

          - type: Query
            field: getBankTransactions
            path: /open-banking/v2/transactions
            method: GET
            argTypeMap:
              valueDate:
                type: object
                properties:
                  from:
                    type: string
                  to:
                    type: string
                required:
                  - from
                  - to
              from:
                type: number
              size:
                type: number
              bookingStatus:
                type: string
            queryStringOptions:
              indices: true
              arrayFormat: brackets
            queryParamArgMap:
              valueDate: valueDate
              from: from
              size: size
              bookingStatus: bookingStatus
            responseSchema: ../json-schemas/greenInvoice.json#/$defs/getBankTransactionsResponse
codegen:
  ignoreEnumValuesFromSchema: false

serve:
  browser: false

sdk:
  generateOperations:
    selectionSetDepth: 5
