-- Insert clip data from RDS to Snowflake
-- This query inserts new records from S3 stage

INSERT INTO {clip_table_name}(
    ID,
    CREATED_AT,
    UPDATED_AT,
    TIME_USED,
    METADATA,
    USER_ID,
    STATUS,
    DISCORD_MESSAGE_ID,
    PROMPT_ID,
    REQUEST_ID,
    IS_GENERATED,
    S3_ID,
    UPVOTE_COUNT,
    BATCH_INDEX,
    MODEL_NAME,
    PROMPT_TEXT,
    DAILY_THEME_ID,
    IS_DELETED,
    IMAGE_S3_ID,
    IS_PUBLIC,
    DISLIKE_COUNT,
    FLAG_COUNT,
    PLAY_COUNT,
    SKIP_COUNT,
    TITLE,
    SLUG,
    P_DATE,
    P_HOUR,
    CREATED_SESSION_ID,
    ALLOW_COMMENTS,
    CREATION_SOURCE,
    IS_HIDDEN,
    DISPLAY_TAGS
)
SELECT 
    $1:id AS id,
    $1:created_at AS created_at,
    $1:updated_at AS updated_at,
    $1:time_used AS time_used,
    $1:metadata AS metadata,
    $1:user_id AS user_id,
    $1:status AS status,
    $1:discord_message_id AS discord_message_id,
    $1:prompt_id AS prompt_id,
    $1:request_id AS request_id,
    $1:is_generated AS is_generated,
    $1:s3_id AS s3_id,
    $1:upvote_count AS upvote_count,
    $1:batch_index AS batch_index,
    $1:model_name AS model_name,
    $1:prompt_text AS prompt_text,
    $1:daily_theme_id AS daily_theme_id,
    $1:is_deleted AS is_deleted,
    $1:image_s3_id AS image_s3_id,
    $1:is_public AS is_public,
    $1:dislike_count AS dislike_count,
    $1:flag_count AS flag_count,
    $1:play_count AS play_count,
    $1:skip_count AS skip_count,
    $1:title AS title,
    $1:slug AS slug,
    '{partition_start_date}'::DATE AS p_date,
    {partition_start_hour} AS p_hour,
    $1:created_session_id AS created_session_id,
    $1:allow_comments AS allow_comments,
    $1:creation_source AS creation_source,
    $1:is_hidden AS is_hidden,
    $1:display_tags AS display_tags
FROM {stage_path} (file_format => 'BASIC_PARQUET_LOADER', pattern => ('.*.parquet'));

