openapi: 3.0.0
info:
  version: 1.0.0
  title: ows-abacus-account API Specifications
servers:
  - url: 'https://qa-ows-abacus-account.theorchard.io'
    description: QA server
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK

  /account/:
    post:
      summary: Creates a new account with the specified details
      requestBody:
        description: The account details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountDetails'
        '400':
          description: Bad data received in payload
        '409':
          description: Account already exists

  /accounts/:
    post:
      summary: Get list of accounts filtered by params
      requestBody:
        description: The account ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountsDetailsPost'
      responses:
        '200':
          description: Retrived
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountsDetails'
        '400':
          description: Bad data received in payload
    get:
      summary: Get list of accounts filtered by params
      parameters:
        - in: query
          name: account_ids
          description: ids of the accounts
          required: false
          schema:
            type: array
            items:
              type: integer
        - in: query
          name: account_name
          description: Name of the account (Deprecated)
          required: false
          schema:
            type: string
        - in: query
          name: search_term
          description: Search term
          required: false
          schema:
            type: string
        - in: query
          name: payment_entity_id
          description: id of the payment entity
          required: false
          schema:
            type: integer
        - in: query
          name: agreement_type_ids
          description: ids of the agreement type
          required: false
          schema:
            type: array
            items:
              type: integer
        - in: query
          name: reference_payment_type_id
          description: id of the payment type
          required: false
          schema:
            type: integer
        - in: query
          name: limit
          description: The number of items to return (for pagination)
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          description: The number of items to skip before returning results (for pagination)
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Retrived
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountsDetails'

  /account/{account_id}/:
    get:
      summary: Retrieves account details
      parameters:
        - description: The ID of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountDetails'
        '404':
          description: 404 NOT FOUND

  /account/{account_id}:
    put:
      summary: Updates an account details
      parameters:
        - description: The ID of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Dict of fields needs to be updated.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPutBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountDetails'
        '400':
          description: Bad data received in payload

  /account/{account_id}/sap:
    get:
      summary: Retrieves sap formatted account details
      parameters:
        - description: ID of an account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SAPFormattedAccountDetails'
        '404':
          description: 404 NOT FOUND

  /account-payee/:
    post:
      summary: Creates a new account_payee with the specified details
      requestBody:
        description: The account_payee details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPayeePostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPayeeDetails'
        '400':
          description: Bad data received in payload

  /account-payee/{account_payee_id}/:
    get:
      summary: Retrieves account_payee details
      parameters:
        - description: The ID of the account_payee
          name: account_payee_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPayeeDetails'
        '404':
          description: 404 NOT FOUND
    put:
      summary: Updates an existing account_payee
      parameters:
        - description: The ID of the account_payee
          name: account_payee_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: The account_payee details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPayeePutBody'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPayeeDetails'
        '400':
          description: Bad data received in payload
        '404':
          description: 404 NOT FOUND

  /account/{account_id}/account-payee/:
    get:
      summary: Retrieves account_payee by account_id
      parameters:
        - description: The ID of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPayeeDetails'
        '404':
          description: 404 NOT FOUND

  /account/dataloader:
    post:
      summary: Dataload accounts by account ids
      requestBody:
        description: The account ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountIdsPostBody'

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                description: List of Accounts details
                items:
                  $ref: '#/components/schemas/DataloadedAccountDetails'
        '400':
          description: Bad data received in payload

  /account-payee/dataloader:
    post:
      summary: Retrieves account_payee by account_payee_id
      requestBody:
        description: The account payee ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPayeeIdsPostBody'

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                description: List of Account Payee details
                items:
                  $ref: '#/components/schemas/DataloadedAccountPayeeDetails'
        '400':
          description: Bad data received in payload

  /account-contract-vat-detail:
    post:
      summary: Insert KNR VAT data for account
      requestBody:
        description: KNR VAT details list
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountKnrContractVatDetailsPostBody'

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                description: List of inserted KNR VAT details
                items:
                  $ref: '#/components/schemas/AccountKnrContractVatDetailsResponse'
        '400':
          description: Bad data received in payload

  /account-payee/dataloader/account:
    post:
      summary: Retrieves account_payee by account_id
      requestBody:
        description: The account ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountIdsPostBody'

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                description: List of Account Payee details
                items:
                  $ref: '#/components/schemas/DataloadedAccountPayeeDetails'
        '400':
          description: Bad data received in payload

  /account/{account_id}/account-payee-history/:
    get:
      summary: Retrieves account_payee_history by account_id
      parameters:
        - description: The ID of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPayeeHistory'
        '400':
          description: Account {account_id} does not exist

  /account/{account_id}/account-tax-info/:
    get:
      summary: Retrieves account_tax_info by account_id
      parameters:
        - description: The ID of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTaxInfoDetails'
        '400':
          description: Account {account_id} does not exist

  /account-tax-info/snapshot/:
    post:
      summary: Return a account tax info in tsv
      requestBody:
        description: List of Account IDs
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: 200 OK
          content:
            text/csv: {}

  /accounts/account-tax-info:
    post:
      summary: Return a list of account tax info
      parameters:
        - in: query
          name: limit
          description: The number of items to return (for pagination)
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          description: The number of items to skip before returning results (for pagination)
          schema:
            type: integer
            default: 0
        - in: query
          name: certificate_of_residence_expiration_date_start
          description: certificate_of_residence_expiration_date start (YYYY-MM-DD)
          required: false
          schema:
            type: string
        - in: query
          name: certificate_of_residence_expiration_date_end
          description: certificate_of_residence_expiration_date end (YYYY-MM-DD)
          required: false
          schema:
            type: string
      requestBody:
        description: Optional list of Account IDs
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTaxInfoList'

  /account-tax-info/{account_tax_info_id}/:
    parameters:
      - description: The ID of the account_tax_info
        name: account_tax_info_id
        in: path
        required: true
        schema:
          type: integer
    get:
      summary: Retrieves account_tax_info by its ID
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTaxInfoDetails'
        '404':
          description: 404 NOT FOUND
    put:
      summary: Updates an existing account_tax_info
      requestBody:
        description: The account_tax_info details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountTaxInfoPutBody'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTaxInfoDetails'
        '400':
          description: Bad data received in payload
        '404':
          description: 404 NOT FOUND

  /account/{account_id}/account-tax-info-history/:
    get:
      summary: Retrieves an account's tax info history
      parameters:
        - description: id of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTaxInfoHistory'
        '400':
          description: Account {account_id} does not exist

  /account-payment-terms/snapshot/:
    post:
      summary: Return a csv of account payment terms
      requestBody:
        description: List of Account IDs
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: 200 OK
          content:
            text/csv: {}

  /account-payment-term/:
    post:
      summary: Creates account-payment-term with the specified details
      requestBody:
        description: The account details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPaymentTermPostSchema'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentTermDetailSchema'

  /account-payment-term/{account_payment_term_id}/:
    get:
      summary: Get account-payment-term's details
      parameters:
        - description: id of an account_payment_term
          name: account_payment_term_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentTermDetailSchema'
        '400':
          description: AccountPaymentTerm {account_payment_term_id} does not exist
    put:
      summary: Updates account-payment-term's details
      parameters:
        - description: id of an account_payment_term
          name: account_payment_term_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Payment term's details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountPaymentTermPutSchema'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentTermDetailSchema'
        '400':
          description: AccountPaymentTerm {account_payment_term_id} does not exist

  /account-payment-term-template/{template_id}/account-payment-term/:
    post:
      summary: Creates account and account-payment-term
      parameters:
        - description: id of a template
          name: template_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Account Id
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                account_id:
                  type: integer
                  description: An id of account
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentTermDetailSchema'

  /account/{account_id}/account-payment-term/:
    get:
      summary: Get account-payment-term's details
      parameters:
        - description: id of an account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentTermDetailSchema'

  /account/account-payment-term/dataloaded:
    post:
      summary: Dataload account payment terms by account ids
      requestBody:
        description: The account ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountIdsPostBody'

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                description: List of Accounts payment term details
                items:
                  $ref: '#/components/schemas/DataloadedAccountPaymentTermDetails'
        '400':
          description: Bad data received in payload

  /eligible-accounts/:
    get:
      summary: Get an eligible accounts list
      parameters:
        - description: id of the payment group
          name: payment_group_id
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/EligibleAccountList'

  /account/{account_id}/payment-hold/:
    get:
      summary: Retrieves a account's payment hold data
      parameters:
        - description: id of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentHoldDetails'
        '400':
          description: Account {account_id} does not exist
    post:
      summary: Creates a payment hold for the account.
      parameters:
        - description: id of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Creates new payment hold for the account. If account already has a payment hold, the existing hold will updated.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PaymentHoldPostSchema'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentHoldDetails'
        '400':
          description: Account {account_id} does not exist || Start date cannot be before today || Account's payment status of {active/on hold} already exists or is pending.

  /account/{account_id}/payment-hold-history/:
    get:
      summary: Retrieves a account's payment hold history
      parameters:
        - description: id of the account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentHoldHistory'
        '400':
          description: Account {account_id} does not exist


  /payment-holds/:
    post:
      summary: Retrieves a list of payment holds with optional filters
      parameters:
        - name: limit
          in: query
          description: Maximum number of items to return
          required: false
          schema:
            type: integer
            default: 100
            minimum: 1
        - name: offset
          in: query
          description: Number of items to skip
          required: false
          schema:
            type: integer
            default: 0
            minimum: 0
      requestBody:
        description: List of account IDs to filter by (optional)
        required: false
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
              example: [123, 456, 789]
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentHoldList'
        '400':
          description: Bad request - invalid parameters

  /account/{account_id}/payment-eligibility-status/:
    parameters:
      - description: ID of an account
        name: account_id
        in: path
        required: true
        schema:
          type: integer
    get:
      summary: Get account's payment eligibility status
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountPaymentEligibilityStatus'
        '404':
          description: 404 NOT FOUND

  /payoneer-program/:
    get:
      summary: Get a list of payoneer programs
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferencePayoneerProgram'

  /payoneer-program/{payoneer_program_id}:
    get:
      summary: Get payoneer program by ID
      parameters:
        - description: payoneer_program unique ID
          name: payoneer_program_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferencePayoneerProgram'

  /payment-entity/{payment_entity_id}/payment-entity-payoneer-program:
    get:
      summary: Get payment_entity_payoneer_program table by payment entity id
      parameters:
        - description: payment_entity unique ID
          name: payment_entity_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentEntityPayoneerProgram'

  /payment-entity-payoneer-programs:
    get:
      summary: Get list of payment_entity_payoneer_program's
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentEntityPayoneerProgramList'

  /payoneer-program-move-type:
    get:
      summary: Resolve move type for a payoneer program transition
      parameters:
        - description: Source payoneer program ID
          name: from_program_id
          in: query
          required: true
          schema:
            type: integer
        - description: Target payoneer program ID
          name: to_program_id
          in: query
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  move_type:
                    type: string
                    enum:
                      - ADOPT_AND_RELEASE
                      - RELEASE_AND_WARN
        '400':
          description: Missing parameters or unsupported transition
        '404':
          description: Program not found

  /reference-agreement-types:
    get:
      summary: Get list of reference_agrement_type's
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceAgreementType'

  /payoneer-program/payment-entity/{reference_payment_entity_id}/currency/{currency_code}/agreement-type/{agreement_type_id}:
    get:
      deprecated: true
      summary:
        'Get payoneer program by params (reference_payment_entity_id, currency_code, agreement_type_id).
        This endpoint is deprecated. Use the extended one that includes payment type'
      parameters:
        - description: id of the related reference_payment_entity
          name: reference_payment_entity_id
          in: path
          required: true
          schema:
            type: integer
        - description: iso3 currency code
          name: currency_code
          in: path
          required: true
          schema:
            type: string
        - description: agreement_type unique ID
          name: agreement_type_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferencePayoneerProgram'
        '400':
          description: Bad data received in payload
        '404':
          description: 404 NOT FOUND

  /payoneer-program/payment-entity/{reference_payment_entity_id}/currency/{currency_code}/agreement-type/{agreement_type_id}/payment-type/{reference_payment_type_id}:
    get:
      summary: Get payoneer program by params (reference_payment_entity_id, currency_code, agreement_type_id, reference_payment_type_id)
      parameters:
        - description: id of the related reference_payment_entity
          name: reference_payment_entity_id
          in: path
          required: true
          schema:
            type: integer
        - description: iso3 currency code
          name: currency_code
          in: path
          required: true
          schema:
            type: string
        - description: agreement_type unique ID
          name: agreement_type_id
          in: path
          required: true
          schema:
            type: integer
        - description: payment_type unique ID
          name: reference_payment_type_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferencePayoneerProgram'
        '400':
          description: Bad data received in payload
        '404':
          description: 404 NOT FOUND

  /payment-group/{payment_group_id}/eligible-accounts:
    get:
      summary: Get a list of eligible accounts for payment group
      parameters:
        - description: id of the payment group
          name: payment_group_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/PaymentGroupEligibleAccountList'

components:
  schemas:
    AccountDetails:
      title: Account GET
      type: object
      properties:
        account_id:
          type: integer
          description: The account ID (same as the vendor_id in art_relations)
        account_name:
          type: string
          description: Name of the account
        account_payee_id:
          type: integer
          description: ID of the child account_payee
        account_payment_term_id:
          type: integer
          description: ID of the child account_payment_term
        sap_created_at:
          type: string
          description: Date on which account details are posted to SAP
      example:
        account_id: 123456
        account_name: 'An Account, not a Vendor'
        account_payee_id: 1
        account_payment_term_id: 3
        sap_created_at: None

    AccountsDetails:
      title: Get Accounts by ids via POST
      type: object
      properties:
        items:
          type: object
          description: Accounts list
          properties:
            account_id:
              type: integer
              description: The account ID (same as the vendor_id in art_relations)
            account_name:
              type: string
              description: Name of the account
            account_payee_id:
              type: integer
              description: The account payee ID
            account_payment_term_id:
              type: integer
              description: Id of an account_payment_term
            sap_created_at:
              type: string
              description: Date on which account details are posted to SAP
            created_by:
              type: string
              description: User who created the payment hold
        total_count:
          type: string
          description: Total finded items
      example:
        account_id: 123456
        account_name: 'An Account, not a Vendor'
        account_payee_id: 1
        account_payment_term_id: 3
        sap_created_at: None
        created_by: 'test_user'

    AccountPostBody:
      title: Account POST
      type: object
      properties:
        account_id:
          type: integer
          description: The account ID (same as the vendor_id in art_relations)
        account_name:
          type: string
          description: Name of the account
        currency_code:
          type: string
          description: An alpha-3 ISO currency code. If present, creates account_payment_term.
        country_of_tax_residence:
          type: string
          description: Account's tax country represented as an alpha-3 ISO country code. If present, creates account_tax_info.
        creation_source:
          type: string
          description: Creation source identifier
      required:
        - account_id
        - account_name
      example:
        account_id: 123456
        account_name: 'An Account, not a Vendor'
        country_of_tax_residence: 'USA'
        currency_code: 'USD'
        creation_source: 'lambda-abacus-sync-account'

    AccountPayeePostBody:
      title: Account Payee POST
      type: object
      properties:
        account_id:
          type: integer
          description: The account ID
        payoneer_payee_id:
          type: integer
          description: The payee ID in the Payoneer system
        payoneer_payee_name:
          type: string
          description: The payee name in the Payoneer system
        payoneer_iframe_url:
          type: string
          description: The iframe url provided by Payoneer
        payoneer_iframe_url_date:
          type: string
          description: The date the iframe url was generated by Payoneer
        payoneer_session_id:
          type: string
          description: The session ID used in the Payoneer system
        reference_payment_type_id:
          type: integer
          description: The payee reference payment type key
        description:
          type: string
          description: Optional description for the account payee (max 250 characters)
          maxLength: 250
      required:
        - account_id
      example:
        account_id: 123456
        payoneer_payee_id: 123123
        payoneer_payee_name: 'Joe Payoneer'
        payoneer_iframe_url: 'payoneer.com/iframe'
        payoneer_iframe_url_date: '2022-02-01'
        payoneer_session_id: 'T-800'
        reference_payment_type_id: 2
        payment_description: 'Sample description'

    AccountPayeeDetails:
      title: Account Payee GET
      type: object
      allOf:
        - $ref: '#/components/schemas/AccountPayeePostBody'
      properties:
        account_payee_id:
          type: integer
          description: The account payee ID
        last_modified:
          type: string
          description: Date the entry was modified
      example:
        account_payee_id: 654321
        account_id: 123456
        payoneer_payee_id: 123123
        payoneer_payee_name: 'Joe Payoneer'
        payoneer_iframe_url: 'payoneer.com/iframe'
        payoneer_iframe_url_date: '2022-02-01'
        payoneer_session_id: 'T-800'
        last_modified: '2022-02-28'
        reference_payment_type_id: null
        payment_description: 'Sample description'

    DataloadedAccountPayeeDetails:
      title: Dataloaded Account Payee list schema
      type: object
      properties:
        data:
          $ref: '#/components/schemas/AccountPayeeDetails'

    DataloadedAccountDetails:
      title: Dataloaded Accounts list schema
      type: object
      properties:
        data:
          $ref: '#/components/schemas/AccountDetails'

    DataloadedAccountPaymentTermDetails:
      title: Dataloaded Account payment term detail list schema
      type: object
      properties:
        data:
          $ref: '#/components/schemas/AccountPaymentTermDetailSchema'

    AccountPayeeHistory:
      title: Account Payee History GET
      type: object
      allOf:
        - $ref: '#/components/schemas/AccountPayeeDetails'
      properties:
        account_payee_history_id:
          type: integer
          description: The account payee history ID
        created_at:
          type: string
          description: Date the entry was created
        last_modified:
          type: string
          description: Date the entry was modified
      example:
        account_payee_history_id: 101010101
        account_payee_id: 654321
        account_id: 123456
        payoneer_payee_id: 123123
        payoneer_payee_name: 'Joe Payoneer'
        payoneer_iframe_url: 'payoneer.com/iframe'
        payoneer_iframe_url_date: '2022-02-01'
        payoneer_session_id: 'T-800'
        created_at: '2022-01-01'
        last_modified: '2022-03-01'

    AccountPayeePutBody:
      title: Account Payee PUT
      type: object
      properties:
        payoneer_payee_id:
          type: integer
          description: The payee ID in the Payoneer system
        payoneer_program_id:
          type: number
          description: Unique ID for the payoneer program, provided by Payoneer
        payoneer_payee_name:
          type: string
          description: The payee name in the Payoneer system
        payoneer_iframe_url:
          type: string
          description: The iframe url provided by Payoneer
        payoneer_iframe_url_date:
          type: string
          description: The date the iframe url was generated by Payoneer
        payoneer_session_id:
          type: string
          description: The session ID used in the Payoneer system
        reference_payment_type_id:
          type: integer
          description: The payee reference payment type key
        description:
          type: string
          description: Optional description for the account payee (max 250 characters)
          maxLength: 250
      example:
        payoneer_payee_id: 123123
        payoneer_payee_name: 'Joe Payoneer'
        payoneer_iframe_url: 'payoneer.com/iframe'
        payoneer_iframe_url_date: '2022-02-01'
        payoneer_session_id: 'T-800'
        reference_payment_type_id: 3
        payment_description: 'Updated description'

    AccountTaxInfoDetails:
      title: Account Tax Info GET
      type: object
      properties:
        account_tax_info_id:
          type: integer
          description: The AccountTaxInfo ID
        account_id:
          type: integer
          description: The account ID
        country_of_tax_residence:
          type: string
          description: Alpha-3 code of the country of tax residence
        is_sba_signed:
          type: boolean
          description: Is SBA signed
        is_vat_exempt:
          type: boolean
          description: Indicates account should be exempt from vat calculations or not
        is_tax_treaty_claimed:
          type: boolean
          description: Is tax treaty claimed or not (relevant for US taxes)
        tax_employment_type:
          type: string
          enum:
            [
              'Business',
              'Employed Individual',
              'Self-Employed Individual (< 2 years)',
              'Self-Employed Individual (>= 2 years)',
            ]
          description: Tax employment type
        certificate_of_residence_expiration_date:
          type: string
          description: Expiration date of the residence certificate
        is_wht_applicable:
          type: boolean
          description: Is WHT applicable
        is_resident_of_spanish_islands:
          type: boolean
          description: Is resident of spanish islands
        wht_rate_override:
          type: number
          description: WHT rate override
      example:
        account_tax_info_id: 123
        account_id: 321
        country_of_tax_residence: 'USA'
        is_sba_signed: false
        is_vat_exempt: false
        is_tax_treaty_claimed: false
        tax_employment_type: 'Business'
        certificate_of_residence_expiration_date: '2025-01-01'
        is_wht_applicable: true
        is_resident_of_spanish_islands: false
        wht_rate_override: '10.01'

    AccountTaxInfoList:
      title: Account Tax Info List
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/AccountTaxInfoDetails'
        total_count:
          type: integer
          description: Items total count

    AccountTaxInfoPutBody:
      title: Account Tax Info PUT
      type: object
      properties:
        country_of_tax_residence:
          type: string
          description: Alpha-3 code of the country of tax residence
        is_sba_signed:
          type: boolean
          description: Is SBA signed
        is_vat_exempt:
          type: boolean
          description: Indicates account should be exempt from vat calculations or not
        is_tax_treaty_claimed:
          type: boolean
          description: Is tax treaty claimed or not (relevant for US taxes)
        tax_employment_type:
          type: string
          enum:
            [
              'Business',
              'Employed Individual',
              'Self-Employed Individual (< 2 years)',
              'Self-Employed Individual (>= 2 years)',
            ]
          description: Tax employment type
        certificate_of_residence_expiration_date:
          type: string
          description: Expiration date of the residence certificate
        is_wht_applicable:
          type: boolean
          description: Is WHT applicable
        is_resident_of_spanish_islands:
          type: boolean
          description: Is resident of spanish islands
        wht_rate_override:
          type: number
          description: WHT rate override
      example:
        country_of_tax_residence: 'USA'
        is_sba_signed: false
        is_vat_exempt: false
        is_tax_treaty_claimed: false
        tax_employment_type: 'Business'
        certificate_of_residence_expiration_date: '2025-01-01'
        is_wht_applicable: true
        is_resident_of_spanish_islands: false
        wht_rate_override: '10.01'

    AccountTaxInfoHistory:
      title: Account Tax Info History GET
      type: object
      allOf:
        - $ref: '#/components/schemas/AccountTaxInfoDetails'
        - type: object
      properties:
        account_tax_info_history_id:
          type: integer
          description: The AccountTaxInfoHistory ID
        created_at:
          type: string
          description: Date the entry was created
        last_modified:
          type: string
          description: Date the entry was modified
      example:
        account_tax_info_history_id: 1
        account_tax_info_id: 321
        account_id: 123
        country_of_tax_residence: 'USA'
        is_sba_signed: false
        created_at: '2022-01-01'
        last_modified: '2022-03-01'

    ContractBalanceList:
      title: Contracts and their Balances
      description: List of contracts with balances
      type: object
      properties:
        contract_id:
          type: integer
          description: The contract ID
        current_balance:
          type: string
          description: balance amount of the contracts
        currency_code:
          type: string
          description: alpha-3 code of the currency
      example:
        contract_id: 12
        current_balance: '234.29'
        currency_code: 'USD'

    EligibleAccountList:
      title: Eligible Accounts List GET
      description: List of accounts eligible for payment
      type: object
      properties:
        contracts_payable:
          type: array
          items:
            $ref: '#/components/schemas/ContractBalanceList'
        current_balance:
          type: string
          description: balance amount of the account
        eligibility_status:
          type: string
          description: is active
        account_id:
          type: integer
          description: The account ID
        account_name:
          type: string
          description: An account's name
        currency_code:
          type: string
          description: alpha-3 code of the currency
        payment_entity_id:
          type: integer
          description: reference payment entity ID
        payment_minimum:
          type: string
          description: minimum amount of money for the account to be payed
        payment_schedule:
          type: string
          description: Payment schedule
        country_of_tax_residence:
          type: string
          description: Country code defining the tax residence
      example:
        contracts_payable:
          - currency_code: 'USD'
            current_balance: '234.32'
            contract_id: 12
        currency_code: 'USD'
        account_name: 'Account 1'
        payment_entity_id: 1
        account_id: 1
        eligibility_status: 'active'
        current_balance: '5000.00'
        payment_minimum: '35.00'
        payment_schedule: '30_days_after_month_end'
        country_of_tax_residence: 'USA'

    PaymentHoldPostSchema:
      title: Payment Hold POST
      type: object
      properties:
        is_on_hold:
          type: boolean
          description: Whether a hold has been placed or removed
        reason:
          type: string
          description: Why the payment hold has been placed or removed
        start_date:
          type: string
          description: Date the hold or removal takes affect
      example:
        is_on_hold: True
        reason: 'They had it coming'
        start_date: '2020-05-01'
      required:
        - is_on_hold
        - reason
        - start_date

    PaymentHoldDetails:
      title: Payment Hold GET
      type: object
      allOf:
        - $ref: '#/components/schemas/PaymentHoldPostSchema'
      properties:
        payment_hold_id:
          type: integer
          description: id of the payment hold
        account_id:
          type: integer
          description: id of the account the hold is applied to
        created_at:
          type: string
          description: Date the hold or removal was entered
        created_by:
          type: string
          description: User who created the payment hold
      example:
        payment_hold_id: 1
        is_on_hold: True
        account_id: 123
        reason: 'They had it coming'
        start_date: '2020-05-01'
        created_at: '2020-05-01'
        created_by: 'test_user'

    PaymentHoldHistory:
      title: Payment Hold History GET
      type: object
      allOf:
        - $ref: '#/components/schemas/PaymentHoldDetails'
      properties:
        payment_hold_history_id:
          type: integer
          description: id of the payment hold history
        end_date:
          type: string
          description: Date the hold or removal ended
      example:
        payment_hold_history_id: 1
        payment_hold_id: 1
        is_on_hold: True
        account_id: 123
        reason: 'They had it coming'
        start_date: '2020-05-01'
        end_date: '2020-05-10'
        created_at: '2020-05-01'
        created_by: 'test_user'

    PaymentHoldList:
      title: Payment Hold List Response
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/PaymentHoldDetails'
          description: List of payment holds
        total_count:
          type: integer
          description: Total number of payment holds matching the filter
      example:
        items:
          - payment_hold_id: 1
            account_id: 123
            is_on_hold: true
            reason: 'They had it coming'
            start_date: '2020-05-01'
            created_at: '2020-05-01'
            created_by: 'test_user'
          - payment_hold_id: 2
            account_id: 456
            is_on_hold: false
            reason: 'Resolved'
            start_date: '2020-06-01'
            created_at: '2020-06-01'
            created_by: 'test_user'
        total_count: 2

    AccountPaymentTermPostSchema:
      title: Account Payment Term POST
      type: object
      properties:
        account_id:
          type: number
          description: Id of an account
        currency_code:
          type: string
          description: three-letter currency code
        payment_entity_id:
          type: number
          description: ID of the reference payment entity
        payment_schedule:
          type: string
          description: One of '30_days_after_month_end','45_days_after_month_end','60_days_after_month_end','90_days_after_month_end','30_days_after_quarter_end','45_days_after_quarter_end','60_days_after_quarter_end','90_days_after_quarter_end'
        payment_minimum:
          type: number
          description: minimum balance account must have before to get paid
        agreement_type_id:
          type: number
          description: Foreign key for related reference_agreement_type
      required:
        - account_id
        - currency_code
      example:
        account_id: 1
        currency_code: 'USD'
        payment_schedule: null
        payment_minimum: null
        agreement_type_id: 1
        payment_entity_id: 1

    AccountPaymentTermPutSchema:
      title: Account Payment Term PUT
      type: object
      properties:
        currency_code:
          type: string
          description: three-letter currency code
        payment_schedule:
          type: string
          description: One of '30_days_after_month_end','45_days_after_month_end','60_days_after_month_end','90_days_after_month_end','30_days_after_quarter_end','45_days_after_quarter_end','60_days_after_quarter_end','90_days_after_quarter_end'
        payment_minimum:
          type: number
          description: minimum balance account must have before to get paid
        agreement_type_id:
          type: number
          description: Foreign key for related reference_agreement_type
        payment_entity_id:
          type: number
          description: ID of the reference payment entity
      example:
        currency_code: 'USD'
        payment_schedule: null
        payment_minimum: null
        agreement_type_id: 1
        payment_entity_id: 1

    AccountPaymentTermDetailSchema:
      title: Account Payment Term GET
      type: object
      allOf:
        - $ref: '#/components/schemas/AccountPaymentTermPostSchema'
      properties:
        account_payment_term_id:
          type: number
          description: Id of an account_payment_term
      example:
        account_payment_term_id: 1
        account_id: 1
        currency_code: 'USD'
        payment_schedule: null
        payment_minimum: null
        agreement_type_id: 1
        payment_entity_id: 1

    AccountPaymentEligibilityStatus:
      title: Account's Payment Eligibility Status GET
      type: object
      properties:
        eligibility_status:
          type: string
          description: Either 'active' or 'on_hold'
      example:
        eligibility_status: 'on_hold'

    ReferencePayoneerProgram:
      title: Payoneer Program GET
      type: object
      properties:
        payoneer_program_id:
          type: number
          description: Unique ID for the payoneer program, provided by Payoneer
        payoneer_program_name:
          type: string
          description: General name for the payoneer program ID and currency
        funding_currency:
          type: string
          description: Currency code for the funding currency
        reference_payment_type_id:
          type: number
          description: Payment type ID
      example:
        payoneer_program_id: 1
        payoneer_program_name: 'AWAL Core - USD'
        funding_currency: 'GBP'
        reference_payment_type_id: 8

    PaymentEntityPayoneerProgram:
      title: Payment Entity Payoneer Program GET
      type: object
      properties:
        payment_entity_payoneer_program_id:
          type: number
          description: Unique ID for payment entity payoneer program table
        payoneer_program_id:
          type: number
          description: Foreign key for related payoneer_program_id
        payment_entity_id:
          type: number
          description: Foreign key for related payment_entity_id
        payment_currency:
          type: string
          description: Currency code for the payment currency
        reference_payment_entity_id:
          type: number
          description: Foreign key for related reference_payment_entity_id
      example:
        payment_entity_payoneer_program_id: 1
        payoneer_program_id: 1
        payment_entity_id: 1
        payment_currency: 'USD'
        reference_payment_entity_id: 1

    SAPFormattedAccountDetails:
      title: SAP formatted account details
      type: object
      properties:
        account_id:
          type: integer
          description: ID of an account (same as the vendor_id in art_relations)
        account_name:
          type: string
          description: Name of an account
        Kunnr:
          type: integer
          description: Customer Number
        Lifnr:
          type: integer
          description: Vendor Number
        Zzfield1:
          type: string
          description: Place Holder 1
        Zzfield2:
          type: string
          description: Place Holder 2
      example:
        account_id: 1
        account_name: 'Test Account'
        Kunnr: None
        Lifnr: None
        Zzfield1: None
        Zzfield2: None

    AccountPutBody:
      title: Account PUT request body
      type: object
      properties:
        account_name:
          type: string
          description: Name of the account
        sap_created_at:
          type: string
          description: Date on which account details are posted to SAP
      required:
        - account_name
        - sap_created_at
      example:
        account_name: 'An Account, not a Vendor'
        sap_created_at: '2022-03-16T14:02:15.000000'

    AccountsDetailsPost:
      title: AccountsDetails POST request body
      type: object
      properties:
        account_ids:
          type: array
          description: Accounts ids
          items:
            type: integer
        account_name:
          type: string
          description: Name of the account (Deprecated)
        search_term:
          type: string
          description: Search term
        payment_entity_id:
          type: number
          description: Payment entity ID to filter accounts
        agreement_type_ids:
          type: array
          description: Agreement type IDs to filter accounts
          items:
            type: integer
        reference_payment_type_id:
          type: number
          description: Payment type ID to filter accounts
        limit:
          type: number
          description: Amount of retrieved items
        offset:
          type: number
          description: From where to start returning data
      example:
        account_ids: [1, 2, 3, 4]

    AccountIdsPostBody:
      title: Account ID's POST request body
      type: array
      items:
        type: integer
        description: Account ids list
      example: [1, 2, 3, 4]

    AccountPayeeIdsPostBody:
      title: AccountsPayee ID's POST request body
      type: array
      items:
        type: integer
        description: Account Payee ids list
      example: [1, 2, 3, 4]

    AccountKnrContractVatDetailsPostBody:
      title: KNR account contract VAT details POST request body
      type: array
      items:
        $ref: '#/components/schemas/KnrVatContractDetails'
      example:
        [
          {
            account_id: 1,
            contract_id: 1,
            company_code: '4719',
            is_vat_eligible: True,
            is_vat_registered: True,
            vat_country: 'United Kingdom',
          },
          {
            account_id: 1,
            contract_id: 2,
            company_code: '4719',
            is_vat_eligible: True,
            is_vat_registered: True,
            vat_country: 'United Kingdom',
          },
        ]

    KnrVatContractDetails:
      title: KNR account contract VAT details
      type: object
      properties:
        account_id:
          type: number
          description: Account id
        contract_id:
          type: number
          description: Account contract id
        company_code:
          type: string
          description: Company code
        is_vat_eligible:
          type: boolean
          description: Is VAT eligible
        is_vat_registered:
          type: boolean
          description: Is VAT registered
        vat_country:
          type: string
          description: VAT country
      example:
        account_id: 1
        contract_id: 1
        company_code: '4719'
        is_vat_eligible: True
        is_vat_registered: True
        vat_country: 'United Kingdom'

    AccountKnrContractVatDetailsResponse:
      title: KNR account contract VAT details response
      type: array
      items:
        $ref: '#/components/schemas/KnrVatContractDetailsResponse'
      example:
        [
          {
            account_contract_vat_detail_id: 1,
            account_id: 1,
            contract_id: 1,
            company_code: '4719',
            is_vat_eligible: True,
            is_vat_registered: True,
            vat_country: 'United Kingdom',
          },
          {
            account_contract_vat_detail_id: 2,
            account_id: 1,
            contract_id: 2,
            company_code: '4719',
            is_vat_eligible: True,
            is_vat_registered: True,
            vat_country: 'United Kingdom',
          },
        ]

    KnrVatContractDetailsResponse:
      title: KNR account contract VAT details item
      type: object
      properties:
        KnrVatContractDetailsResponse:
          type: number
          description: ID
        account_id:
          type: number
          description: Account id
        contract_id:
          type: number
          description: Account contract id
        company_code:
          type: string
          description: Company code
        is_vat_eligible:
          type: boolean
          description: Is VAT eligible
        is_vat_registered:
          type: boolean
          description: Is VAT registered
        vat_country:
          type: string
          description: VAT country
      example:
        account_id: 1
        contract_id: 1
        company_code: '4719'
        is_vat_eligible: True
        is_vat_registered: True
        vat_country: 'United Kingdom'

    PaymentEntityPayoneerProgramList:
      title: Payment Entity Payoneer Program List details
      type: object
      properties:
        payoneer_program_id:
          type: number
          description: Foreign key for related payoneer_program_id
        payment_currency:
          type: string
          description: An alpha-3 ISO currency code for the payment currency
        agreement_type:
          type: string
          description: List of comma-separated related reference_agreement_type names
        reference_agreement_type_id:
          type: string
          description: List of comma-separated ID's of related reference_agreement_type
        reference_payment_entity_id:
          type: string
          description: Foreign key for related reference_payment_entity
        reference_payment_type_id:
          type: number
          description: Foreign key for related reference_payment_type
        payment_service:
          type: string
          description: Payment service name from reference_payment_type
      example:
        payoneer_program_id: 1
        payment_currency: 'USD'
        agreement_type: 'AWAL Core, AWAL +'
        reference_agreement_type_id: '1,2'
        reference_payment_entity_id: 1
        reference_payment_type_id: 7
        payment_service: 'service'

    ReferenceAgreementType:
      title: Reference Agreement Type details
      type: object
      properties:
        reference_agreement_type_id:
          type: number
          description: Reference agreement type id
        agreement_type:
          type: string
          description: Type of related reference_agreement_type
      example:
        reference_agreement_type_id: 1
        agreement_type: 'AWAL Core'

    PaymentGroupEligibleAccountList:
      title: Eligible Accounts List GET
      description: List of accounts eligible for payment group
      type: object
      properties:
        contracts:
          type: array
          items:
            type: integer
        account_id:
          type: integer
          description: The account ID
        account_name:
          type: string
          description: An account's name
        currency_code:
          type: string
          description: alpha-3 code of the currency
        payment_entity_id:
          type: integer
          description: reference_payment_entity_id
        payment_minimum:
          type: string
          description: minimum amount of money for the account to be payed
        payment_schedule:
          type: string
          description: Payment schedule
        country_of_tax_residence:
          type: string
          description: Country code defining the tax residence
      example:
        contracts: [1, 2, 3]
        currency_code: 'USD'
        account_name: 'Account 1'
        payment_entity_id: 1
        account_id: 1
        payment_minimum: '35.00'
        payment_schedule: '30_days_after_month_end'
        country_of_tax_residence: 'USA'
