{% snapshot m_DWH_FXCD_NH_F_CLEARER %}
{{
    config(
      target_schema='dw_rar',
      alias = 'NH_F_CLEARER_MARS',
      unique_key=['CLEARER_ID'],
      strategy='check',
      check_cols=['ENTITY_ID',
                  'ELIGIBILITY_OF_FLAG',
                  'ELIGIBILITY_FR_FLAG',
                  'ACTIVE_FLAG',
                  'OVERALL_OF_LIMIT_AMT',
                  'CASH_OF_LIMIT_AMT',
                  'SECURITIES_OF_LIMIT_AMT',
                  'OVERALL_FR_LIMIT_AMT',
                  'CASH_FR_LIMIT_AMT',
                  'SECURITIES_FR_LIMIT_AMT'],
      hard_deletes='invalidate',
      dbt_valid_to_current="TIMESTAMP '9999-12-31 00:00:00'",
      snapshot_meta_column_names={
        'dbt_valid_from': 'A_VALID_FROM',
        'dbt_valid_to': 'A_VALID_TO',
        'dbt_updated_at': 'UPDATED_AT',
        'dbt_scd_id': 'SCD_ID'
      },
      column_types={
        'A_VALID_FROM': 'DATE',
        'A_VALID_TO': 'DATE'
      },
      tags=["m_DWH_FXCD_NH_F_CLEARER"]
    )
}}
SELECT
   (SELECT COALESCE(MAX(A_KEY), 0) FROM {{ this }}) + ROW_NUMBER() OVER (ORDER BY 1) as A_KEY,
   {{ get_workflow_history_key() }} AS A_DWH_LOAD_SET_FK,
   CLEARER_ID,
   ENTITY_ID,
   {{clean_boolean_fxcd('ELIGIBILITY_OF_FLAG')}} AS ELIGIBILITY_OF_FLAG,
   {{clean_boolean_fxcd('ELIGIBILITY_FR_FLAG')}} AS ELIGIBILITY_FR_FLAG,
   {{clean_boolean_fxcd('ACTIVE_FLAG')}} AS ACTIVE_FLAG,
   OVERALL_OF_LIMIT_AMT,
   CASH_OF_LIMIT_AMT,
   SECURITIES_OF_LIMIT_AMT,
   OVERALL_FR_LIMIT_AMT,
   CASH_FR_LIMIT_AMT,
   SECURITIES_FR_LIMIT_AMT
FROM {{ source('ods', 'F_CLEARER') }}
WHERE 
    A_WORKFLOW_HISTORY_KEY = {{ filter_workflow_history_max_key("w_ODS_FXCD_F_CLEARER",get_main_task_name(model.name))}}
{% endsnapshot %}

