package <%= packageName %>.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description Xxl-Job Configuration
 **/
@Configuration
public class XxlJobConfiguration {

    private final ApplicationProperties properties;
    private final Logger log = LoggerFactory.getLogger(XxlJobConfiguration.class);


    public XxlJobConfiguration(ApplicationProperties properties) {
        this.properties = properties;
    }

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        ApplicationProperties.XxlJob xxlJob = properties.getXxlJob();
        String adminAddresses = xxlJob.getAdminAddresses();
        String address = xxlJob.getAddress();
        String appName = xxlJob.getAppName();
        String ip = xxlJob.getIp();
        Integer port = xxlJob.getPort();
        String accessToken = xxlJob.getAccessToken();
        String logPath = xxlJob.getLogPath();
        Integer logRetentionDays = xxlJob.getLogRetentionDays();

        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setAddress(address);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);

        return xxlJobSpringExecutor;
    }
}
