package com.samsung.batch.excutor;

import com.samsung.accesslog.SysUseLogService;
import lombok.extern.log4j.Log4j2;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Log4j2
public class SysUseLogBatchExecutor extends QuartzJobBean {

    @Value("${node-id}")
    private String nodeId;

    @Autowired
    private SysUseLogService sysUseLogService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        String jobName = jobDetail.getKey().getName();
        log.info(new StringBuilder()
                .append("nodeId : ").append(nodeId).append(", ")
                .append("jobName : ").append(jobName).append(", ")
                .append("description : ").append(jobDetail.getDescription())
        );
        switch (jobName) {
            case "batchSysUseLog" -> {
                try {
                    sysUseLogService.loadBatchData("");
                } catch (IOException e) {
                    log.error(e.getMessage());
                }
            }
            case "batchMenuUseHistory" -> sysUseLogService.executeMenuUseHistory("");
            default -> {
            }
        }
    }
}
