CREATE OR REPLACE TASK SUNO_PROD.PROD.FACT_CREDIT_TOPUP_DAILY_INSERT
    WAREHOUSE = SUNO_PROD_X_SMAL
    SCHEDULE = 'USING CRON 0 6 * * * UTC'
AS
DECLARE
    p_date VARCHAR;
    row_count NUMBER;
    start_time TIMESTAMP;
BEGIN
    start_time := CURRENT_TIMESTAMP();
    p_date := DATE(SYSDATE() - INTERVAL '1 DAY');
    CALL fact_credit_topup_proc(:p_date);

    SELECT COUNT(*) INTO :row_count
    FROM suno_prod.prod.fact_credit_topup
    WHERE p_date = :p_date;
    CALL TASK_MONITOR_INSERT_PROC('FACT_CREDIT_TOPUP_DAILY_INSERT', :start_time, :row_count, 'SUCCESS', 'DAILY');
END;
