-- User hCaptcha History table for storing hCaptcha validation history from RDS
-- This table is populated by the Glue job rds_to_s3_bots_userhcaptchahistory_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 {user_hcaptcha_history_table_name} CLUSTER BY (p_date, p_hour) (
    -- Primary identifier
    ID VARCHAR(255),                                    -- Unique hCaptcha history record identifier
    
    -- Timestamps
    CREATED_AT TIMESTAMP_TZ(9),                         -- When the record was created
    UPDATED_AT TIMESTAMP_TZ(9),                         -- Last update timestamp
    
    -- hCaptcha data
    TOKEN VARCHAR(16777216),                            -- hCaptcha token
    PASSED BOOLEAN,                                     -- Whether the captcha was passed
    SCORE FLOAT,                                        -- hCaptcha score (0.0-1.0)
    HCAPTCHA_RESPONSE VARCHAR(16777216),                -- Full hCaptcha response data
    
    -- Request metadata
    IP_ADDRESS VARCHAR(255),                            -- IP address of the request
    
    -- References
    USER_ID NUMBER(38,0),                               -- ID of the user
    
    -- 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
);

