package com.caliverse.admin.scheduler;

import com.caliverse.admin.domain.entity.InGame;
import com.caliverse.admin.domain.entity.Mail;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.config.ScheduledTask;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;

@Service
public class ScheduleService {

    private final Map<String, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();

    private final Map<Long, Mail> mailTask = new ConcurrentHashMap<>();
    private final Map<Long, InGame> noticeTask = new ConcurrentHashMap<>();

    public boolean isTaskExist(String key){
        return scheduledTasks.containsKey(key);
    }

    public void addTask(String key, ScheduledFuture<?> schdule){
        scheduledTasks.put(key, schdule);
    }

    public void closeTask(String key) {
        ScheduledFuture<?> scheduledFuture = scheduledTasks.get(key);
        if (scheduledFuture != null) {
            scheduledFuture.cancel(true);
            scheduledTasks.remove(key);
        }
    }

//    public boolean isTaskExist(String type, Long id) {
//        switch (type) {
//            case "mail" -> {
//                return mailTask.containsKey(id);
//            }
//            case "notice" -> {
//                return noticeTask.containsKey(id);
//            }
//            default -> {
//                return false;
//            }
//        }
//    }
//
//    public void createTask(Mail mail) {
//        mailTask.put(mail.getId(), mail);
//    }

}
