CREATE TRANSIENT TABLE IF NOT EXISTS suno_prod.prod.fact_credit_topup (
    -- Primary key and user identifiers
    id VARCHAR NOT NULL PRIMARY KEY COMMENT 'Unique ID for this credit topup. MD5 hash of billing provider name, user ID, provider customer ID, and provider invoice/transaction ID.'
    , user_id NUMBER(38,0) COMMENT 'User ID (null for deleted users)'
    , user_uid VARCHAR COMMENT 'User UID (null for deleted users)'

    -- Billing provider information
    , billing_provider VARCHAR COMMENT 'Name of billing provider (Stripe, RevenueCat). Stripe for web, RevenueCat for iOS and Android'
    , purchased_on_platform VARCHAR COMMENT 'Platform on which the credit topup was purchased (web, ios, android)'
    , provider_customer_id VARCHAR COMMENT 'Stripe customer ID or Revcat app user ID (which is sometimes the Suno user UID)'
    , provider_transaction_id VARCHAR COMMENT 'Stripe invoice ID or Revcat transaction ID'

    -- Credit topup information
    , n_credits NUMBER(38,0) COMMENT 'Number of credits added to user''s balance'
    , purchased_ts_utc TIMESTAMP_NTZ(9) COMMENT 'Timestamp of credit topup'
    , provider_product_id VARCHAR COMMENT 'For Stripe, the product ID of the credit topup. For RevenueCat, null (RevenueCat does not use product IDs)'
    , provider_product_name VARCHAR COMMENT 'Product name of the credit topup'
    , amount_usd NUMBER(38,2) COMMENT 'Transaction amount in USD'
    , amount_local NUMBER(38,2) COMMENT 'Transaction amount in local currency'
    , currency_code VARCHAR COMMENT 'Transaction currency code'

    , p_date DATE COMMENT 'Date of credit topup'
) CLUSTER BY (p_date)
COMMENT = 'All credit topups on any platform'
