version: 2
models:
  - name: gov__fact_validators
    description: "{{ doc('fact_validators') }}"
    recent_date_filter: &recent_date_filter
      config:
        where: modified_timestamp >= current_date - 7
    recent_date_filter_and_exclude_records: &recent_date_filter_and_exclude_records
      config:
        where: modified_timestamp >= current_date - 7 and NOT (node_pubkey = 'KtKiqBftjVcPR9WNi8dyoXoajj4xWtebf8enapgDv2Y' AND epoch in (666,667,668)) and NOT (node_pubkey = '2ViH5QVqCX3LjsCHBniMN2yfUEVc6W2cp9M6m6ZpVpxi' AND epoch = 667) and NOT (node_pubkey = 'isusUYC5gwsBpARY4Mf8wnFahMDVCtvPp91VBnR81yF' AND epoch = 668)
        # API response returned null values for these validators from epochs 666-668 so excluding from tests
    tests:
      - reference_tx_missing:
          reference_tables:
            - 'silver__snapshot_validators_app_data'
          id_column: 'node_pubkey'
    columns:
      - name: epoch
        description: "{{ doc('epoch') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
      - name: node_pubkey
        description: "{{ doc('node_pubkey') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
      - name: vote_pubkey
        description: "{{ doc('vote_pubkey') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
      - name: active_stake
        description: "{{ doc('active_stake') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - null_threshold:
              threshold_percent: 0.99 # api returns null for some validators
              where: modified_timestamp >= current_date - 7
      - name: admin_warning
        description: "{{ doc('admin_warning') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: avatar_url
        description: "{{ doc('avatar_url') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: commission
        description: "{{ doc('commission') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - null_threshold:
              threshold_percent: 0.99 # api returns null for some validators
              where: modified_timestamp >= current_date - 7
      - name: created_at
        description: "{{ doc('created_at') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
      - name: data_center_key
        description: "{{ doc('data_center_key') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: data_center_host
        description: "{{ doc('data_center_host') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: delinquent
        description: "{{ doc('delinquent') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - null_threshold:
              threshold_percent: 0.99 # api returns null for some validators
              where: modified_timestamp >= current_date - 7
      - name: details
        description: "{{ doc('details') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: epoch_active
        description: "{{ doc('epoch_active') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: epoch_credits
        description: "{{ doc('validator_epoch_credits') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: keybase_id
        description: "{{ doc('keybase_id') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: latitude
        description: "{{ doc('latitude') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: longitude
        description: "{{ doc('longitude') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: validator_name
        description: "{{ doc('validator_name') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: software_version
        description: "{{ doc('software_version') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - null_threshold:
              threshold_percent: 0.99 # api returns null for some validators
              where: modified_timestamp >= current_date - 7
      - name: updated_at
        description: "{{ doc('updated_at') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
      - name: www_url
        description: "{{ doc('www_url') }}"
        tests:
          - dbt_expectations.expect_column_to_exist
      - name: FACT_VALIDATORS_ID
        description: '{{ doc("pk") }}'
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter
          - unique: *recent_date_filter
      - name: INSERTED_TIMESTAMP
        description: '{{ doc("inserted_timestamp") }}'
        tests:
          - dbt_expectations.expect_column_to_exist
          - not_null: *recent_date_filter 
      - name: MODIFIED_TIMESTAMP
        description: '{{ doc("modified_timestamp") }}'
        tests:
          - dbt_expectations.expect_column_to_exist