package com.example.quiz.utils;

import java.time.Duration;
import java.time.LocalDateTime;

public class SessionManager {
    // 10 minutes en millisecondes
    private static final long sessionExpiredTime =   10 * 60 * 1000;

    private LocalDateTime lastExpiredDate;

    public SessionManager() {}

    public void updateLastExpiredDate() {
        lastExpiredDate = LocalDateTime.now();
    }

    public boolean isExpired() {
        if (lastExpiredDate == null) {
            return true;
        }
        // Vérifie si le temps écoulé depuis lastExpiredDate > sessionExpiredTime
        Duration elapsed = Duration.between(lastExpiredDate, LocalDateTime.now());
        return elapsed.toMillis() > sessionExpiredTime;
    }
}
