package com.takensoft.cms.mber.Schedule;

import com.takensoft.cms.mber.dao.RefreshTokenDAO;
import com.takensoft.common.exception.CustomUpdateFailException;
import org.springframework.dao.DataAccessException;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
 * @author  : takensoft
 * @since   : 2024.04.01
 * @modification
 *     since    |    author    | description
 *  2024.04.01  |  takensoft   | 최초 등록
 *
 * RefreshToken 만료 기한이 된 token 제거를 위한 스케쥴러
 */
@Component
public class RefreshScheduler {

    private final RefreshTokenDAO refreshTokenDAO;
    public RefreshScheduler(RefreshTokenDAO refreshTokenDAO) {
        this.refreshTokenDAO = refreshTokenDAO;
    }

    /**
     * refresh token 삭제 스케쥴러
     * 매일 자정에 만료 기한이 지난 refresh token 삭제
     */
    @Scheduled(cron = "0 0 0 * * *")
    @Transactional(rollbackFor = Exception.class)
    public void cleanExpiredRefreshTokens() {
        refreshTokenDAO.cleanExpiredRefreshTokens();
    }
}
