-- Exécuter ceci dans phpMyAdmin ou MySQL Workbench

SET GLOBAL event_scheduler = ON;

-- Événement 1
DROP EVENT IF EXISTS daily_cleanup;
CREATE EVENT daily_cleanup
ON SCHEDULE EVERY 1 DAY
STARTS CURRENT_TIMESTAMP
DO
DELETE FROM jwt_refresh_tokens WHERE expires_at < NOW();

-- Événement 2  
DROP EVENT IF EXISTS reset_api_counters;
CREATE EVENT reset_api_counters
ON SCHEDULE EVERY 1 DAY
STARTS CURRENT_TIMESTAMP
DO
UPDATE api_keys 
SET calls_today = 0, 
    last_reset_date = CURDATE() 
WHERE last_reset_date < CURDATE() OR last_reset_date IS NULL;

-- Vérification
SELECT * FROM INFORMATION_SCHEMA.EVENTS;