package com.samsung.config;

import com.samsung.batch.excutor.UserBatchExecutor;
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 UserBatchConfig {

    @Value("${batch.user.long-term-check.cron}")
    private String batchUserLongTermCheckCron;
    
    @Value("${batch.user.auth-expired.cron}")
    private String batchUserAuthExpiredCron;
    
    @Value("${batch.user.auth-expired-mailing.cron}")
    private String batchUserAuthExpiredMailingCron;
    
    @Value("${batch.user.sync.cron}")
    private String batchUserSyncCron;

    /**
     * 장기 미사용자 관리 Job
     */
    @Bean
    public JobDetail batchUserLongTermCheckJob() {
         return JobBuilder
                .newJob(UserBatchExecutor.class)
                .withIdentity("batchUserLongTermCheck")
                .withDescription("User LongTerm Check Batch")
                .storeDurably(true)
                .build();
    }

    /**
     * 장기 미사용자 관리 Trigger
     */
    @Bean
    public CronTriggerFactoryBean batchUserLongTermCheckTrigger() {
        CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
        trigger.setJobDetail(batchUserLongTermCheckJob());
        trigger.setCronExpression(batchUserLongTermCheckCron);
        return trigger;
    }
    
    /**
     * 만료 권한 삭제 Job
     */
    @Bean
    public JobDetail batchUserAuthExpiredJob() {
        return JobBuilder
                .newJob(UserBatchExecutor.class)
                .withIdentity("batchUserAuthExpired")
                .withDescription("User Auth Expired Batch")
                .storeDurably(true)
                .build();
    }
    /**
     * 만료 권한 삭제 Trigger
     */
    @Bean
    public CronTriggerFactoryBean batchUserAuthExpiredTrigger() {
    	CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
        trigger.setJobDetail(batchUserAuthExpiredJob());
    	trigger.setCronExpression(batchUserAuthExpiredCron);
    	return trigger;
    }

//    /**
//     * 권한 만료 안내 메일 Job
//     * @return
//     */
//    @Bean
//    public JobDetail batchUserAuthExpiredMailingJob() {
//        return JobBuilder
//                .newJob(UserBatchExecutor.class)
//                .withIdentity("batchUserAuthExpiredMailing")
//                .withDescription("User Auth Expired Mailing Batch")
//                .storeDurably(true)
//                .build();
//    }
//    /**
//     * 권한 만료 안내 메일 Trigger
//     * @return
//     */
//    @Bean
//    public CronTriggerFactoryBean batchUserAuthExpiredMailingTrigger() {
//    	CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
//    	trigger.setJobDetail(batchUserAuthExpiredMailingJob());
//    	trigger.setCronExpression(batchUserAuthExpiredMailingCron);
//    	return trigger;
//    }
//
//    /**
//     * 사용자 동기화 Job
//     * @return
//     */
//    @Bean
//    public JobDetail batchUserSyncJob() {
//        return JobBuilder
//                .newJob(UserBatchExecutor.class)
//                .withIdentity("batchUserSync")
//                .withDescription("User Sync Batch")
//                .storeDurably(true)
//                .build();
//    }
//    /**
//     * 사용자 동기화 Trigger
//     * @return
//     */
//    @Bean
//    public CronTriggerFactoryBean batchUserSyncTrigger() {
//    	CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
//    	trigger.setJobDetail(batchUserSyncJob());
//    	trigger.setCronExpression(batchUserSyncCron);
//    	return trigger;
//    }
}