-- Drop existing event if it exists
DROP EVENT IF EXISTS `auto_refresh_otp_event`;

-- Create the event to automatically refresh expired OTPs
-- This event runs every 1 minute and calls AutoRefreshExpiredOTPs()
-- The updated procedure now handles multiple OTPs per pass using field_uid
CREATE EVENT `auto_refresh_otp_event` 
ON SCHEDULE EVERY 1 MINUTE 
STARTS NOW() 
ON COMPLETION PRESERVE 
ENABLE 
DO 
    CALL AutoRefreshExpiredOTPs();
