package com.samsung.config;

import com.samsung.batch.excutor.SysUseLogBatchExecutor;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;

@Configuration
public class SysUseLogBatchConfig {
	
	@Value("${batch.sys-use-log.menu-use-history.cron}")
    private String menuUseHistoryCron;
	
    @Value("${batch.sys-use-log.menu-utilization.cron}")
    private String menuUtilizationCron;

    @Bean
    public JobDetail batchMenuUseHistoryJob() {
        return JobBuilder
                .newJob(SysUseLogBatchExecutor.class)
                .withIdentity("batchMenuUseHistory")
                .withDescription("MenuUseHistory Batch")
                .storeDurably(true)
                .build();
    }

    @Bean
    public CronTriggerFactoryBean batchMenuUseHistoryTrigger() {
        CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
        trigger.setJobDetail(batchMenuUseHistoryJob());
        trigger.setCronExpression(menuUseHistoryCron);
        return trigger;
    }

    @Bean
    public JobDetail batchSysUseLogJob() {
         return JobBuilder
                .newJob(SysUseLogBatchExecutor.class)
                .withIdentity("batchSysUseLog")
                .withDescription("batchSysUseLog Batch")
                .storeDurably(true)
                .build();
    }

    @Bean
    public CronTriggerFactoryBean batchSysUseLogTrigger() {
        CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
        trigger.setJobDetail(batchSysUseLogJob());
        trigger.setCronExpression(menuUtilizationCron);
        return trigger;
    }
}