-- Discount Offer table for storing discount offer data from RDS
-- This table is populated by the Glue job rds_to_s3_billing_discountoffer_hourly_upsert
-- which dumps data from RDS to S3 and then loads it into Snowflake
-- Clustered by partition date and hour for optimal query performance
CREATE TRANSIENT TABLE IF NOT EXISTS {discount_offer_table_name} CLUSTER BY (p_date, p_hour) (
    -- Primary identifier
    ID VARCHAR(255),                                    -- Unique discount offer identifier
    
    -- Timestamps
    CREATED_AT TIMESTAMP_TZ(9),                         -- When the discount offer was created
    UPDATED_AT TIMESTAMP_TZ(9),                         -- Last update timestamp
    
    -- Discount details
    STRIPE_COUPON_ID VARCHAR(255),                      -- Stripe coupon identifier
    PERCENT_OFF INTEGER,                                -- Percentage discount (if applicable)
    AMOUNT_OFF INTEGER,                                 -- Fixed amount discount (if applicable)
    DURATION_MONTHS INTEGER,                            -- Number of months the discount is valid
    
    -- Partitioning columns for optimization
    P_DATE DATE,                                        -- Partition date based on created_at
    P_HOUR NUMBER(38,0)                                 -- Partition hour (0-23) based on created_at
);

