{%- set incremental_predicate = partition_filter_daily('DBT_INTERNAL_DEST.p_date') -%}
{{
    config(
        materialized='incremental',
        incremental_strategy='delete+insert',
        incremental_predicates=[incremental_predicate],
        unique_key=['user_id', 'user_uid', 'platform', 'p_date'],
        cluster_by=['p_date'],
        snowflake_warehouse='FACT_PLAY_BACKFILL_SMALL',
    )
}}

-- Filter spine to only active days (where users had any activity on the platform)
SELECT
    user_id
    , user_uid
    , subscription_tier
    , platform
    , clip_total_count
    , gen_clip_total_count
    , play_count
    , play_duration_seconds
    , unique_play_duration_seconds
    , play_breakdown
    , hook_create_count
    , hook_play_count
    , hook_play_duration_seconds
    , hook_unique_play_duration_seconds
    , hook_play_breakdown
    , is_high_intent_listening
    , high_intent_listening_breakdown
    , is_active
    , engagement_flags
    , total_following_cnt
    , total_follower_cnt
    , net_likes_received_count
    , historical_activity
    , p_date
    , days_since_user_joined
FROM {{ ref('agg_user_platform_daily_spine') }}
WHERE {{ partition_filter_daily('p_date') }}
    AND is_active = TRUE
