package com.caliverse.admin.scheduler.polling.service;

import com.caliverse.admin.domain.entity.log.LogAction;
import com.caliverse.admin.global.component.manager.BusinessProcessIdManager;
import com.caliverse.admin.mongodb.service.BusinessLogService;
import com.caliverse.admin.scheduler.CommonScheduler;
import com.caliverse.admin.scheduler.ScheduleService;
import com.caliverse.admin.scheduler.entity.SchedulerType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class cleanupScheduler extends CommonScheduler {

    private final ScheduleService scheduleService;

    public cleanupScheduler(ScheduleService scheduleService,
                            BusinessLogService businessLogService,
                            BusinessProcessIdManager processIdManager) {
        super(businessLogService, processIdManager);
        this.scheduleService = scheduleService;
    }

    @Override
    protected void executeInternal() {
        executeWithProcessId(LogAction.SCHEDULE_CLEANUP, this::executeLogic);
    }

    private void executeLogic() {
        scheduleService.cleanupCompletedTasks();
        scheduleService.cleanupMailTasks();
        scheduleService.cleanupNoticeTasks();
    }

    @Override
    public SchedulerType getSchedulerType() {
        return SchedulerType.CLEAN_UP;
    }
}
