package com.its.api.scheduler;

import com.its.api.config.JobConfig;
import com.its.api.scheduler.job.CctvPsetScnrJobThread;
import com.its.api.scheduler.job.FcltSttsJobThread;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

@Slf4j
@AllArgsConstructor
@EnableScheduling
@Component
public class ItsApiScheduler {

    private final JobConfig jobConfig;
    private final CctvPsetScnrJobThread cctvPsetScnrThread;
    private final FcltSttsJobThread fcltSttsJobThread;

    @PreDestroy
    public void onShutDown() {
    }

    /**
     * CCTV Preset 제어 스케줄러
     */
    @Async
    @Scheduled(cron = "0 * * * * *")  // 1분 주기 작업 실행
    public void jobCctvPsetScnr() {
        if (this.jobConfig.isCctvPreset()) {
            log.info("START CctvPsetScnrJob");
            this.cctvPsetScnrThread.run();
        }
    }

    @Async
    @Scheduled(cron = "0/30 * * * * *")  // 30초 주기 작업 실행
    public void pollingFcltStts() {
        log.info("START FcltSttsJob");
        fcltSttsJobThread.run();
    }

    @Async
    @Scheduled(cron = "0/2 * * * * *")  // 2초 주기 작업 실행
    public void checkKafkaServerAlive() {
    }

}
