version: 2
models:
  - name: silver___pre_token_balances
    recent_date_filter: &recent_date_filter
      config:
        where: _inserted_timestamp >= current_date - 7
    tests:
      - dbt_utils.unique_combination_of_columns:
          combination_of_columns:
            - BLOCK_ID
            - TX_ID
            - INDEX
          where: block_timestamp::date > current_date - 7
    columns:
      - name: BLOCK_TIMESTAMP
        description: "{{ doc('block_timestamp') }}"
        tests:
          - not_null: *recent_date_filter
          - dbt_expectations.expect_row_values_to_have_recent_data:
              datepart: day
              interval: 2
      - name: BLOCK_ID
        description: "{{ doc('block_id') }}"
        tests:
          - not_null: *recent_date_filter
      - name: TX_ID
        description: "{{ doc('tx_id') }}"
        tests:
          - not_null: *recent_date_filter
      - name: SUCCEEDED
        description: "{{ doc('tx_succeeded') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: INDEX
        description: Location of the pre token balance entry within the array for a transaction
        tests: 
          - not_null: *recent_date_filter
      - name: ACCOUNT_INDEX
        description: Location corresponding to the index in the accounts array 
        tests: 
          - not_null: *recent_date_filter
      - name: MINT
        description: "{{ doc('mint') }}"
        tests: 
          - not_null: *recent_date_filter
      - name: OWNER
        description: Address of the owner of the token account
        tests: 
          - not_null:
              where: block_id > 111492264 and _inserted_timestamp >= current_date - 7 # before this we don't have owner from figment
      - name: DECIMAL 
        description: Number of decimals in the token value, need to divide amount by 10^decimal
        tests: 
          - not_null: *recent_date_filter
      - name: UIAMOUNT
        description: Amount of the token in the transaction 
        tests: 
          - not_null: *recent_date_filter
      - name: UIAMOUNTSTRING
        description: Amount of the token in the transaction in string format
        tests: 
          - not_null: *recent_date_filter
      - name: _INSERTED_TIMESTAMP
        description: "{{ doc('_inserted_timestamp') }}"
        tests: 
          - not_null