package de.cannamanage.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Scheduled task to clean up expired revoked tokens.
 * Runs daily at 03:00 to remove tokens whose expiration has passed
 * (they can no longer be used anyway, so the revocation record is stale).
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TokenCleanupScheduler {

    private final TokenRevocationService tokenRevocationService;

    @Scheduled(cron = "0 0 3 * * *")
    public void cleanupExpiredTokens() {
        log.info("Starting expired token cleanup...");
        int deleted = tokenRevocationService.cleanupExpiredTokens();
        log.info("Expired token cleanup complete: {} tokens removed", deleted);
    }
}
