package com.samsung.config;

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

    @Value("${knox.approval.sync.cron}")
    private String knoxApprovalSyncCron;

    @Bean
    public JobDetail knoxApprovalSyncJobDetail() {
        return JobBuilder
                .newJob(KnoxSyncBatchExecutor.class)
                .withIdentity("knoxApprovalSyncJob")
                .withDescription("Knox Approval Sync Batch")
                .storeDurably(true)
                .build();
    }

    @Bean
    public CronTriggerFactoryBean knoxApprovalSyncTrigger() {
        CronTriggerFactoryBean approvalTrigger = new CronTriggerFactoryBean();
        approvalTrigger.setJobDetail(knoxApprovalSyncJobDetail());
        approvalTrigger.setCronExpression(knoxApprovalSyncCron);
        return approvalTrigger;
    }
}